I have a form which is used to update a shopping cart for a site I’m building. I have a quick cart at the top of the page which gets the number of items and the price of the item and times the two together to get a total. Simple enough. In my main cart I have the option to adjust the quantity of the product in the cart, which on submit will refresh the page and update the table and in doing so, re-calculate the cart and quick cart amounts. This works but it’s not updating the quick cart unless I resubmit the form. In other words, I have to enter the amount and click submit and click the submit button again for the quick cart to update.
I’ve looked at the query and the quantity is updated straight away. The price field however is not updating until it’s submitted again. Here’s some code to explain further;
Here’e the query code
<?php
if (@$_POST['go']=='2') {
$itemPrice = $_POST['cost'];
$itemID = (int)($_POST['orderLine']);
$itemQty = (int)($_POST['prodquantity']);
if(isset($itemID)) {
$sql = "UPDATE order_items SET quantity = '$itemQty', price = '$itemPrice' WHERE itemID = '$itemID'";
$perform_insert = mysql_query($sql) or die(mysql_error());
unset ($itemID);
unset ($itemQty);
unset ($itemPrice);
header("Location: cart.html");
}
}
?>
Here is the form. The item price is pulled form another table and submitted as a hidden value.
<?php
$hp = $price;
echo '<form action="" method="post">';
echo '<input type="text" size="1" name="prodquantity" value = "' . $row['quantity'] . '" />';
echo '<input type="image" src="images/refresh.png" border="0" alt="update" height="20px" height="20px" />';
echo '<input type="hidden" name="go" value="2">';
echo '<input type="hidden" name="cost" value="' . $hp . '">';
echo '<input type="hidden" name="orderLine" value="' . $row['itemID'] . '">';
echo '</form>';
?>
What I don’t understand is why it’s not updating the price but will update the quantity on the form submit. The price is entered into a table as a decimal (5,2). Can anyone help?