I'm using cookies to collect info for a shopping cart at check out time when the user clicks on check the items will be inserted into the database. (Mysql)
Problem is how to loop a query thought the cookie and insert each row it finds as a row in the database.
Here's the code not working.
<?php
// Get the information about all the items selected by the user
$query= "select from catalog where " ;
for($i=0; $i<$total_items; $i++)
if ($i == ($total_items-1))
$query .= "cat_id = '$items_tray[$i]' " ;
else
$query .= "cat)id = '$items_tray[$i]' or " ;
if (!($result1 = mysql_db_query($DB,$query))) {
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit() ;
}
$j=1 ;
$total=0 ;
while (($row = mysql_fetch_array($result1))){
// Find the item number
for($i=0; $i < $total_items; $i++){
if ($row["cat_id"] == $items_tray[$i])
break ;
}
if (($i == $total_items) || ($quantity[$i] == 0))
continue ;
// Insert the transaction in the Database
$query_insert = "insert into transaction
(user_id,item_no,quantity,date,status)
VALUES
('$cookie_user','$items_tray[$i]','$quantity[$i]','$date','Pending')";
if (!($result_insert = mysql_db_query($DB, $query_insert))){
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit() ;
}
$total=$total+($row["price"] $quantity[$i])
?>
Hope some one can help
if there is a better way please let me know
TIA
Richie TM