Page 1 of 1

problem updating quantity

Posted: Thu Jul 10, 2008 12:39 pm
by swissbeets
i need to be able to update my quantity of products from the shopping cart page, but when i get to the code it does nothing here is where it starts

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>
it posts the information and then i get it on the cart.php page

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
 
at this step is does nothign but shows me the cart.php which is basically never even supposed to be seen

Re: problem updating quantity

Posted: Thu Jul 10, 2008 1:25 pm
by califdon
Your HTML form INPUT type for that field is invalid. There is no such type as "int", it should be "text". The field in the table is probably INT, but all <INPUT> tags are essentially text.

Re: problem updating quantity

Posted: Thu Jul 10, 2008 4:20 pm
by swissbeets
thank you