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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.