0

hi! I'm pretty new to php and i just want to ask how to update tables in mysql using php?

here's my code snippet

            $product_code = $_POST['pCode'];
            $submit = $_POST['submit'];
            $user = $_SESSION['username'];
            $quantity = $_POST['quantity'];
            $price = 300.00;
            $date = date("Y-m-d",mktime()); 

        require('connect.php');
if($submit)
        {
        if($product_code)
            {


        mysql_query("INSERT INTO `order` VALUES ('','$user','$product_code',
        '$price','$quantity','$date')");

                $query1 = mysql_query("UPDATE ed SET stock = stock - $quantity 
                where product_code = $product_code");

        die ("<center><font size = 5><br>Item added to Cart. <br>Continue shopping?
        <a href = ED.php>Y</a>
        |<a href = homepage.html>N</a>
        $query1");


        }
else echo "</ br>Select Product Code";
}

it inserts the values into order but did not update or subtract the $quantity value from the stock in the 'ed' table. can anyone help?

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by mionazraelmiranda
0

If product code is a string, you may need single quotes around your variable, just like you did in the insert query.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.