problem updating quantity

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swissbeets
Forum Newbie
Posts: 20
Joined: Thu Jun 26, 2008 7:56 pm

problem updating quantity

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: problem updating quantity

Post 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.
swissbeets
Forum Newbie
Posts: 20
Joined: Thu Jun 26, 2008 7:56 pm

Re: problem updating quantity

Post by swissbeets »

thank you
Post Reply