Code: Select all
<form method="POST" action="cart.php"> <input type="hidden" name="id" value="<?php echo $row['product_id']; ?>" /> <input type="hidden" name="price" value="<?php echo $row['product_price']; ?>" /> <p> <tr> <?php echo $row['product_name']; ?></tr> <tr> </tr> <tr> $<?php echo $row['product_price']; ?></tr> <br /> <tr> Size: <?php echo $row['size']; ?> </tr> <input type="int" name="qty" value="<?php echo $qty; ?>" maxlength = "3" size = "3" /> <input type="submit" value="Update Quantity" /> <br /><br /> <input type="submit" name="action" value="delete" /> </p> </form>Code: Select all
$cart = $_SESSION['cart'];
$action = $_POST['action'];
$product_id = $_POST['id'];
$size = $_POST['size'];
$product_price = $_POST['price'];
$product_name = $_POST['name'];
$qty = $_POST['qty'];
echo $action;
switch ($action) {
case 'add':
$query = "INSERT INTO cart (
product_id, size, product_price, product_name , qty) VALUES (
'$product_id', '$size', '$product_price', '$product_name', '$qty'
)";
$result = mysql_query($query, $connection);
if (mysql_affected_rows() == 1) {
// Success
//$message = "The product was successfully updated.";
$result = $cart;
//echo $cart;
redirect_to('products.php');
}
echo "MySQL error ". mysql_error();
case 'delete':
$query = "DELETE FROM cart WHERE cart_id = {$product_id} LIMIT 1";
$result = mysql_query($query, $connection);
if (mysql_affected_rows() == 1) {
// Success
//$message = "The product was successfully updated.";
$result = $cart;
//echo $cart;
redirect_to('shoppingcart.php');
}
break;
case 'update':
$qty = $_POST['qty'];
$query = "UPDATE cart SET 'qty' = $qty";
$result = mysql_query($query, $connection) or die("Could not execute query " . mysql_errno());
$record = mysql_fetch_array($result) or die(sprintf("Could not execute query (%d): %s", mysql_errno(), mysql_error()));
redirect_to('shoppingcart.php');
break;
}//case action