cant seem to understand why am I getting this error, any help would much be appreciated

Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5')' at line 1 in /home/ubuntu/workspace/pset7/vendor/library50-php-5/CS50/CS50.php on line 352

my code for buy.php where I am getting the error is

if($cashinhand < $numshares * $stock["price"])
        apologize("You can not afford these shares");
        $word = strtoupper($_POST["symbol"]);

        // updating database with new entry
        CS50::query("INSERT INTO portfolios (user_id, symbol, shares) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(?)", $_SESSION["id"], $word, $numshares, $numshares);

        // updating users cash
        $cashused = $numshares * $stock["price"];

        CS50:: query("UPDATE users SET cash = cash - ? WHERE id = ? ", $cashused, $_SESSION["id"]);


1 Answer 1


The answer is of course to use VALUES(column name) per http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values! :-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .