This time I need help . . .
I have two scripts: one that shows a shopping cart contents and one that removes one item from that cart (=table) when someone hits the "remove" button. Problem is that it always remove the last record added to the cart (table).
Here is the part fo the script that displays the content of the cart:
$get_cart = "SELECT SEL_ITEM, SEL_ITEM_NAME, SEL_ITEM_QTY, SEL_ITEM_PRICE, SEL_ITEM_TOTALPRICE FROM USER_TRACK WHERE USER_ID = \"$user_id\"";
$cart_result = mysql_query($get_cart)
or die("Couldn't get cart.");
while ($row = mysql_fetch_array($cart_result)) {
$sel_item = $row["SEL_ITEM"];
$sel_item_title = $row["SEL_ITEM_NAME"];
$sel_item_qty = $row["SEL_ITEM_QTY"];
$sel_item_price = $row["SEL_ITEM_PRICE"];
$sel_item_totalprice = $row["SEL_ITEM_TOTALPRICE"];
$fmt_item_totalprice = sprintf("%0.2f",$sel_item_totalprice);
echo "
<tr>
<td>$sel_item</td>
<td>$sel_item_title</td>
<td align=right>$sel_item_qty</td>
<td align=right>$ $sel_item_price</td>
<td align=right>$ $fmt_item_totalprice</td>
<td>
<form method=\"post\" action=\"shop_removefromcart.php3\">
<input type=\"hidden\" name=\"remove\" value=\"$sel_item\">
<input type=\"submit\" name=\"submit\" value=\"Remove\"></p>
</td>
</tr>
";
}
And here is the script that removes (delete from the table):
$sql = ("delete from USER_TRACK where SEL_ITEM = \"$remove\" AND USER_ID = \"$user_id\"");
$sql_result = mysql_query($sql,$connection)
or die ("Couldn't delete record!");
echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=shop_viewcart.php3\"></head>";
I believe that I somehow always set the value of $remove to the last item but how can I avoid that?
I am a beginner and learn as I go . . . this must be obvious to most of you but I couldn't find an explanation in the excellent PHP Professional Programming . . .