Hi,

Can anyone please help me with this sql query?

This code is for use in a shopping cart, I am not sure how to get it to subtract '1' from the 'quantity' row in the table.

include("../CMS/script-files/db-connect.php");

$SQL = " UPDATE products SET";
    $SQL = $SQL . " quantity = '??? MINUS 1' WHERE id = '$id'";

    #execute SQL statement
    $result = mysql_db_query($db,"$SQL",$cid);

    # check for error
    if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

    mysql_close($cid);

    Have you tried:

    $SQL = $SQL . " quantity = quantity-1 WHERE id = '$id'";

      Hi,

      Thanks for the reply 🙂

      What type does the 'quantity' field need to be for this to work?

      I did a test and quantity now equals 'quantity - 1' instead of a number ?

        maybe "int", maybe "number" it depends on ....

        but ill guess it should be int

          got it working 🙂

          I removed the space between '- 1'

          Thanks guys 😃

            Write a Reply...