I have been working a long time in buy.php and everything works but if I buy the same stock (AAPL) twice it insert a new row into table despite they have de same id, and symbol.

                //Pass it to capital leters

                query("INSERT INTO `Tabla para quotes` (id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)", $_SESSION["id"],$simbolo, $_POST["shares"]);
                //New chash
                query("UPDATE users SET cash = cash - ?  WHERE `id`=?",$costo,$_SESSION["id"]);
                //redirect to index


Please help!


1 Answer 1


Check your table structure with phpmyadmin: there should be an index id_symbol of type BTREE unique not null.

  • Thanks!! the problem was that I forgot to index them in phpmyadmin, now works fine :)
    – Naxel21
    Commented Nov 3, 2014 at 12:15

You must log in to answer this question.

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