mtran
06-01-2006, 07:44 AM
Hi, I have a View basket page, which works fine in showing a list of items at first. In this same View Basket page, I include a button/form with checkbox to delete any item out. When users select a checkbox and click Update, this leads them to the reserve_edit page, and right back to this updated View basket page.
The problem is: When I select any item, or 2 or more items and click Update, ONLY ONE item always gets deleted: the last item in the table.
Could you help me out of this? I know my description is not very clear, but I hope someby could help.
Here's my View Basket page code:
<?php
$username=$_COOKIE['log'];
$query="SELECT * FROM cart WHERE username='$username' AND status=''"; //initial status is blank.
$result=mysql_query($query,$connection);
?>
<form name='edit' method='post' action='reserve_edit.php'>
<table width="590"class="basket">
<tr class='basket_header'>
<td width='12%'height="35">Remove</td>
<td width='34%' >Title</td>
<td width='15%'>Number reserved </td>
<td width='12%'>From-to</td>
<td width='12%'>Cost</td>
<td width='15%'>Pickup date </td>
</tr>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr class='basket'>
<td><input type='checkbox' name='delete' value='d'>
<input name='id' type='hidden' value='%s'></td>
<td><a href='listing_detail_m.php?id=%s'>%s</a></td>
<td>%s %s</td>
<td>%s</td>
<td>$%s</td>
<td>%s</td></tr>",
$row["id"],$row["id"],$row["title"],$row["number"],$row["type"],$row['from_to'],$row["cost"],$row["pickup"]); } ?>
</table>
<br>
<input type="submit" name="update" value="Update" class="btn">
</form>
Here's my reserve_edit page code:
<?php
require "config.php";
$username=$_COOKIE['log'];
$status=$_POST['delete'];
$id=$_POST['id'];
$result = mysql_query("UPDATE cart SET status='$status' WHERE username='$username' AND id='$id'");
header("Location: reserve_basket.php");
?>
The problem is: When I select any item, or 2 or more items and click Update, ONLY ONE item always gets deleted: the last item in the table.
Could you help me out of this? I know my description is not very clear, but I hope someby could help.
Here's my View Basket page code:
<?php
$username=$_COOKIE['log'];
$query="SELECT * FROM cart WHERE username='$username' AND status=''"; //initial status is blank.
$result=mysql_query($query,$connection);
?>
<form name='edit' method='post' action='reserve_edit.php'>
<table width="590"class="basket">
<tr class='basket_header'>
<td width='12%'height="35">Remove</td>
<td width='34%' >Title</td>
<td width='15%'>Number reserved </td>
<td width='12%'>From-to</td>
<td width='12%'>Cost</td>
<td width='15%'>Pickup date </td>
</tr>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr class='basket'>
<td><input type='checkbox' name='delete' value='d'>
<input name='id' type='hidden' value='%s'></td>
<td><a href='listing_detail_m.php?id=%s'>%s</a></td>
<td>%s %s</td>
<td>%s</td>
<td>$%s</td>
<td>%s</td></tr>",
$row["id"],$row["id"],$row["title"],$row["number"],$row["type"],$row['from_to'],$row["cost"],$row["pickup"]); } ?>
</table>
<br>
<input type="submit" name="update" value="Update" class="btn">
</form>
Here's my reserve_edit page code:
<?php
require "config.php";
$username=$_COOKIE['log'];
$status=$_POST['delete'];
$id=$_POST['id'];
$result = mysql_query("UPDATE cart SET status='$status' WHERE username='$username' AND id='$id'");
header("Location: reserve_basket.php");
?>