I've been implementing buy and I found that I'm having some trouble with inserting the values into users. I received a RuntimeError near "transaction" where I INSERT INTO users ('transaction') VALUES(:cash).

Why am I receiving this RuntimeError? Thanks in advance.

Here is buy:

// edited out

Here is a screenshot of the table users:enter image description here

  • @DinoCoderSaurus I used the answer from that question (quotes around transaction) but I still get the error. Is there something I'm doing wrong? I replaced all of my transaction with 'transaction'. Jun 5 '17 at 17:03
  • Please add a schema listing of the users table and the cash table. What does users.transaction represent? Jun 5 '17 at 17:33
  • I edited my question (See above.) I only had one table (users) and I couldn't find any transaction table. Only the cash has been added, which might be from my earlier attempts at solving this problem. Jun 5 '17 at 17:48

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 transactions, but don't call it transaction, it's just a pain in the neck. (Generally speaking, in every language, avoid using reserved words to name things.) If you added a transaction table but do not see it here, it is likely that you have two finance.db. When you call phpliteadmin finance.db it will look for the db file in the current working directory, and if it is not found it will be created. So maybe there is a finance.db in pset7 directory? In any case, move on, don't call the table transaction, remember to call phpliteadmin from the finance directory.

It looks like the insert_cash line is not appropriate for the buy method.

It looks like you want listed_cash to be the amount of cash the user currently has. Therefore, your select will be from the users table. (There is no table named cash).

It looks like buying should be updating the cash in the users record. Review the sql, there's a mistake. (There is no table named cash).

Use the sqlite doc to review the syntax of INSERT, UPDATE and SELECT statements (specifically the use of table names and column names).

A quick cheat sheet:

SELECT column_names FROM table_name
INSERT INTO table_name (columns) VALUES (values)
UPDATE table_name set column_name = value

The code does not look overly complicated nor long. This method does a lot of verifying, a lot of arithmetic and a lot of updating.

  • I'm slightly confused. How exactly would I insert transaction into the users table? I went into finance and used phpliteadmin finance.db but there is still no transaction table. (I'll rename it to something else. Thank you, by the way!) Jun 6 '17 at 0:31
  • You do not insert transaction into the users table. You CREATE a new table that holds the transactions data. Jun 6 '17 at 1:18
  • Thank you for this. I'm using INSERT INTO users (4) VALUES(...) with the values being the ones I used in the code I provided. However, this produces a syntax error. Is there any reason why? Jun 6 '17 at 11:34
  • The only place you should INSERT INTO users is in register. Full stop. Did you mean INSERT INTO transactions? And (4) is meaningless. Did you use that as a placeholder for the 4 column names in the transactions table? Jun 6 '17 at 12:32
  • I did use (4) as the column names, yes. I used INSERT INTO users because there is no transactions table in users (I checked again with phpliteadmin finance.db). The cash is updating, but no data is being saved (price, time, etc.). When I use INSERT INTO transactions, I get a RuntimeError complaining that the table transactions doesn't exist. Jun 6 '17 at 14:40

You must log in to answer this question.

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