I am creating a facility to update a piece of information on my website. This information is in the form of a quantity; entered by the user.
The first time they enter a quantity it is a doddle, I use the post method to insert the value into a mysql database. This I then call again on the 'shopping cart' page.
So the problem is, I want the user to be able to update this quantity.
I have so far:
An 'Update' form button next to each record in the cart, which posts the value of the 'quantity' text box once more to the page 'edit.php' , (this time with supposably a different value in it (the value to be edited)).
Then on the 'edit.php' page I use this code:
$plu = $_POST['plu'];
$qty = $_POST['qty'];
$_SESSION['plu'] = $plu;
$_SESSION['qty'] = $qty;
switch($_REQUEST['action']){
case 'update':
update();
break;
default:
error();
break;
}
if (isset($HTTP_POST_VARS['update']))
{
update();
}
I then use this function:
function update(){
mysql_query("UPDATE cart SET qty = '".$_SESSION['qty']."' WHERE plu = '".$_SESSION['plu']."'") or die ("An error occured. Please try again");
echo "<font face='Verdana, Arial, Helvetica, sans-serif' size='2'>Item updated successfully</font>";
echo "<BR><BR><HR size='1' color='#336633' NOSHADE>";
echo "<font face='Verdana, Arial, Helvetica, sans-serif' size='2'>Click <A HREF='shopping_basket.php?action=display'>here</a> to return to your shopping basket</font>";
}
But for some reason, I can only successfully update the very bottom item in my cart, so basically the 'Update' button is not referencing individual records.
Any help would be greatly appreciated. Thanks.
Or if anyone could suggest another way of updating the quantity, that would be great; I am sure there are lots more ways of doing this. Ta.
RESOlVED
The most simple thing. My form was surrounding my whole table (when displaying the contents) which means that the update function can only recognise and relate to one row! I simply moved the form into a single row of the table, and now it works great!
RESOLVED