0

I get ( ! ) Fatal error: Duplicate entry 'ihor-BCE' for key 'user_id_2' in /home/ubuntu/workspace/pset7/vendor/library50-php-5/CS50/CS50.php on line 352

I thought that the supplied code was supposed to avoid that. Yes I have user_id and symbol joined. for first time buy I use this INSERT and it works great, its the repeat buys that I have the issue with. I use username as "user_id", not the number....for the "holdings table(portfolio). ` $add = CS50::query("INSERT INTO holdings (shares, symbol, user_id) VALUES(?,?,?)",$_POST["quantity"],$symbol,$_SESSION["user"]);

    }
    else
    {
   $increment = CS50::query("INSERT INTO holdings (user_id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)",
                        $_SESSION["user"],$symbol,$_POST["quantity"]);
    }
    //adjust cash
    $decrement = CS50::query("UPDATE users SET cash = cash - ? WHERE username = ?", $value, $_SESSION["user"]);

    // add to history
    $history = CS50::query("INSERT IGNORE INTO history (user_id, symbol,shares, price, trans) VALUES(?,?,?,?,BUY)",
      $_SESSION["user"], $symbol, $_POST["quantity"],$price);
    `

Interesting, I tried adding the shares then do the DELETE then INSERT and CS50 still gave me the error.......HELP!!

1 Answer 1

-1

Decided to avoid the issue. Did the following: (this is for buy.php) get number of existing shares add the number being bought DELETE the table entry for that stock-user_id combo INSERT the new values.

Up yours CS50::query

You must log in to answer this question.

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