There are two problems I have been mulling over... Hopefully someone with a fresh perspective will catch my mistakes!Cleaned up question to make it easier to understand :)
Q1. The first is that the ID from the Users table is going into the ID column of theIn my Portfolio table, notwhenever I buy or sell shares, the Users_id columnshares update in a single row, whose ID is 0. Even if I feel like this has to do with my INSERT querylog in Buy and Sellwith a different username, sothe shares update here they are:
For, even when I buy:
CS50::query("INSERT INTO portfolio (user_id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)", $_SESSION["id"], $symbol, $_POST["shares"]);
For Sell:
CS50::query("DELETE FROM portfolio WHERE user_id = ? AND symbol = ?", $_SESSION["id"], $symbol);
Q2 shares with a different symbol. This is Basically my code for getting the balance:
$users = CS50::query("SELECT * FROM users WHERE id =Portfolio table looks like this right now ?", $_SESSION["id"]);
$balance = $users[0]["cash"];
render("balance" => $balance]It only has one row); :
I read that you have to do $users[0]["cash"] because query gets an array. But when I do Buy or Sell, all the shares go into a row where ID and User_id are bothId = 0. ; User_id = 11; Symbol = F; Shares = 30
I've followed the walkthrough pretty closely, so I'm not sure where I'm stumblingThis is my index. Thanks for any help at all php code:)
$stock["name"], "price" => number_format($stock["price"], 2, '.', ''), "shares" => $row["shares"], "symbol" => strtoupper($row["symbol"]) ]; } } $users = CS50::query("SELECT * FROM users WHERE id = ?", $_SESSION["id"]); $balance = $users[0]["cash"]; render("portfolio.php", ["positions" => $positions, "title" => "Portfolio", "balance" => $balance]); And this is how my Portfolio and Users tables are laid out: **Portfolio** ID: int(10), UNSIGNED, Primary User_id: int(11), Unique Symbol: varchar(255), Unique Shares: int(11) **Index** ID: int(10), UNSIGNED, Primary Username: varchar(255), Unique Hash: varchar(255) Cash: decimal(65,4), UNSIGNED There are other problems too but hopefully I can figure them out once this one is sorted. Thanks for any help at all :)