0

This is my code for buy.php.

I think the issue is with my SQL line, which is

"INSERT INTO Stocks (user_id, symbol, shares) VALUES(?, ?, ?) 
    ON DUPLICATE KEY UPDATE shares = ?", $_SESSION["id"], 
                             $symbol, $number, $new_shares

My code takes the money away, but does not insert new rows or update stocks in the stocks database.

0

Try this instead:

$temp = CS50::query("INSERT INTO Stocks (user_id, symbol, shares) VALUES(?, ?, ?)
     ON DUPLICATE KEY UPDATE shares = shares + $number", 
                      $_SESSION["id"], $symbol, $number);
1
  • That doesn't work either. No errors still but the database doesn't update the shares. Still takes the money. – DSmith Aug 30 '16 at 16:27
0

Fixed, error was in the database. I was no auto-incrementing the id. Changing this resolved the issue.

1
  • Can I ask what you did to fix this. I have the same problem and I know I should use a UNIQUE key with stock and user_id, but I can't figure out how..please help me with some info on this..thanks – cfdphd Mar 15 '17 at 18:41

You must log in to answer this question.

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