Hot answers tagged

3 votes
Accepted

pset7 - how to get current id?

From the C$50Finance spec Hints re the execute method: If str is a SELECT, then execute returns a list of zero or more dict objects, inside of which are keys and values representing a table’s ...
user avatar
2 votes
Accepted

Column count doesn't match value count at row 1

Edited original answer. You have your INSERT INTO syntax incorrect. Syntax should be: INSERT INTO tablename (Table Col1, Table Col2, etc.) VALUES (? marks for variables, static items enclosed in ...
user avatar
  • 1,317
2 votes
Accepted

pset7 buy - ON DUPLICATE KEY syntax question

'ON DUPLICATE KEY UPDATE' is MySQL syntax. But is this really what you need to do? Remember from the spec: Add one or more new tables to finance.db via which to keep track of the purchase. Store ...
user avatar
2 votes
Accepted

Struggle passing values from Python to HTML via Flask

From the flask doc (Rendering Templates): To render a template you can use the render_template() method. All you have to do is provide the name of the template and the variables you want to pass ...
user avatar
2 votes
Accepted

pset7 question about tables in buy

Ok, I may be wrong about this and I can delete my answer so it stays unanswered if I am. I think the spec is a little murky referenced by Dino on the question linked above. Dino interpreted it to ...
user avatar
2 votes
Accepted

Pset 7 buy - help!!

it seems like when I select the cash value from my SQL table, it is producing a list Quite true. From the Hints section of the spec: If str is a SELECT, then execute returns a list of zero or ...
user avatar
2 votes
Accepted

Pset7 buy - RuntimeError sqlite3.OperationalError near transaction

transaction is a sqlite reserved word. You'll need to escape the column name with quotes (eg 'transaction') or create the table again and rename the column.
user avatar
2 votes
Accepted

pset7 buy typeError can't multiply

I think the line if price * shares > cash: might be problematic on multiple stages. Here, price would be the float, and shares the sequence. shares is probably a string and needs conversion to ...
user avatar
  • 20.7k
2 votes
Accepted

What's the error?-PSET7/buy

According to the error message, this is an Operational Error. Your error message says: (Background on this error at: http://sqlalche.me/e/e3q8) That link point to a paragraph describing the ...
user avatar
2 votes
Accepted

Pset7 buy portfolio values are null

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 > ...
user avatar
  • 302
2 votes

Pset7 buy portfolio values are null

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 ...
user avatar
  • 20.7k
2 votes
Accepted

PSET9 Finance: Check50 says Buy doesn't handle fractional/invalid shares, but when I try these things my page does reject them. Why check50 no like?

So my first question is, where does it come from? It's either bootstrap or the browser. check50 does not use the front end to make the API calls. Therefore any limits put on the html, while GREAT for ...
user avatar
1 vote
Accepted

pset7 finance portfolio table won't update with buy function

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 ...
user avatar
  • 63.1k
1 vote
Accepted

Portfolio not updating in SQLite, Problem Set 7, Buy

The error is caused by the SQL command to INSERT failing because the table 'portfolio' doesn't exist. Create the table and then it should work. :)
user avatar
  • 18.3k
1 vote
Accepted

cs50 pset7 buy syntax error

I would expect you to have an autoincrementing id field that is the primary key (so each transaction has an id) and then a user_id field that holds the user_id for the transaction (that is not unique)....
user avatar
  • 18.3k
1 vote
Accepted

pset7 buy function stopped working... not inserting to portfolio

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 ...
user avatar
  • 63.1k
1 vote
Accepted

can someone please help me with why I am getting internal server error after I enter the symbol and no. and click on buy ?pset7

From your error message: line 143, in buy name=info["name"], ... \ KeyError: 'name' The issue appears to be the 'KeyError' 'name': name=info["name"] Does your dictionary 'info' have a key called ...
user avatar
1 vote
Accepted

Pset7 - buy updates shares in portfolio but not cash in users

The problem is here db.execute=("UPDATE users SET cash= cash -:purchase WHERE id=:id", id = session["user_id"]). You are binding :purchase but you never set it to anything.
user avatar
1 vote

pset7 buy sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near ",": syntax error [SQL: "SELECT * FROM portfolio WHERE user_id= 16, sy

Ok, I found mistake - after WHERE if there is few conditions there have to be an AND between them
user avatar
1 vote

CS50 pset7 buy, Runtime Error: Too many statements

Just a small typo here :name;. Easy to miss, hard to find. (; is the sql delimiter, so "it" thinks you are trying to run 2 sqls).
user avatar
1 vote
Accepted

Pset7 Buy - data re-submitted when I Reload page

You need to use the Post/Redirect/Get design pattern. By doing return render_template("buydisplay.html", rows = rows, cash = cashi), you are "staying" in the buy form with method "POST", so a ...
user avatar
1 vote
Accepted

`RuntimeError: no such column: user_id` pset7 [buy]

I solved it using this link Challenge inserting into database from buy() as a resource. The problem was with the placement of my quotes I changed db.execute("INSERT INTO transactions (user_id, ...
user avatar
  • 231
1 vote
Accepted

Problem Set 7 - Buy - RuntimeError

The error from this sql INSERT INTO users ('transaction') VALUES(:cash) (quotes or not) is because there is no column named transaction in the users table. Now is the perfect time to add a table for ...
user avatar
1 vote
Accepted

Pset7: How to get "Bought!" Alert in /Index when re-directing from /Buy (I tried IF condition, but failed)

@dinocodersaurus's link :) flash ("Bought") return redirect(url_for("index"))
user avatar
  • 179
1 vote
Accepted

Challenge inserting into database from buy()

I vote sophisticated :) The problem is :transaction_date, or lack thereof.
user avatar
1 vote
Accepted

pset7 buy SQL syntax error

Here is the documentation for sqlite SELECT. The '.' represents the delimiter in a schema-name.table-name.column-name result-column expression.
user avatar
1 vote

pset7 buy SQL syntax error

Enclose the column name within square brackets . i.e [users.id] Just a suggestion, avoid using '.' character in sql attribute names.
user avatar
1 vote
Accepted

Pset7. I don't know how to handle POST request of 'finance-buy'. Need help

And I can't see '666666' in my command console. Assuming you mean the browser console, that is not where you should be looking. Since application.py is running on the server, any print messages will ...
user avatar
1 vote
Accepted

pset7 buy - error msg that doesn't make sense?

You need to use bound parameters in the VALUES clause (with the exception of datetime('now')), otherwise names will be interpreted as string literals. Something like db.execute("INSERT INTO ...
user avatar
1 vote
Accepted

pset7 Buy - cant get holdings to update

See if this rings any bells.... INSERT INTO portfolio (id, symbol, shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE ... If this answers your question, please click on the check ...
user avatar
  • 63.1k

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