4

To solve this issue, you need 2 variables. Let's call them $userinfo and $cash. First use query() to get cash value from the row with the id that is contained in $_SESSION. Then use this line of code to put the cash value into $cash. $cash = $userinfo[0]["cash"]; Then you can put cash in print, and it will print out the user's cash.


3

Got it!!!! Used the table align CSS attribute <tbody align="left"> <tr> <td>foo</td> </tr> </tbody>


2

buy should not contain a session["user_id"] =, you would overwrite the user id of the current session that way. The only place for that is login. That might be what causes the error message, you assign None or some number to that variable, but probably not a valid user ID. You don't use id in SQL statement, you should add user_id to the list of columns and ...


2

I can see a couple of things that you may consider changing and also most of your code is correct,so just few things to add on! The code where you are inserting values after checking that cash > stock in the else part as below : else: session["user_id"]=db.execute("INSERT INTO portfolio (stock, shares, balance) ...


2

I think it should be ul (the lowercase letter 'L') not u1


2

The render() function takes two arguments, the first is a string that indicates the name of the template, and the second is an array of key-value pairs. In this case "positions" is a string that represents the key and $positions is the value. Note that the value can be any kind of type, an integer, float, string, etc... or in this case is another array. ...


2

Yes your logic is correct, and this is exactly the way the world works. Say I have $20. I buy a diamond for $10. So now I have $10 left. In a week from now, the same diamond, costs $5. But I still have $10 left, not $15. My current cash balance is not determined by the value of the things I bought at past. It stays the same. Now say I also buy this diamond. ...


1

Suggest you add the desired fields to the portfolio dicts. In the for row in portfolio: loop, something like row['name'] = share['name'] for example. When portfolio is sent to the html, each row will be self-contained.


1

You have to assign a PRIMARY column. In fact, there should be several primary columns for this table, because you don't need several rows with the same shares for one user. There is good explanation in courseware about this table.


1

Have you looked at all of the error or other messages returned? The portfolio table has 6 fields, all of which are NOT NULL and don't appear to have defaults, but the insert and update sql code only inserts 3 fields. I'll wager that the inserts/updates are being rejected because the remaining 3 fields aren't being supplied. If this answers your question, ...


1

I have a number of questions that may answer your issue. Does it still work if you create a new user and "buy" a new stock? Does it work for an old user and a new stock that nobody has bought? Does it work for a new user and an old stock that someone else has bought? Is the user making an additional purchase of stock that they already own? What are the ...


1

@dinocodersaurus's link :) flash ("Bought") return redirect(url_for("index"))


1

You have answered yourself: Is it because the rows themselves are associative arrays, and so I can never actually extract a single value? If that's the case, how would I just pass one variable out of an associative array? CS50::query() returns a normal integer indexed array of rows and each row is an associative array. So, all things considered, the ...


1

Oh. My. Goodness. My 2nd test condition wasn't a valid stock (just some random capital letters that I thought looked like an actual stock symbol) so if ($stock !== false) would kill the foreach() loop, thus only filling $positions with one index. On the plus side, in searching high and low for the answer to this ridiculous error I now understand what's ...


1

I know you said that you have already done this, but please open a new Terminal tab in ide50, and execute the following commands: mysql50 shell SHOW DATABASES; USE `pset7`; SHOW TABLES; exit Then paste the output of this command into your original question, and press Ctrl+K (or click the {} button in the editor) to format as a code block. This will allow ...


1

There is no way anyone was going to get this with what I posted. I think the problem comes from the fact that I copy and pasted this from notes I was taking on Zamyla's video. The key came when I realized the double-quote before SELECT was white but the one after the question mark was green. I have been fooling around with this for a while and I must have ...


Only top voted, non community-wiki answers of a minimum length are eligible