0

I am trying to update my history table using the below query:

 // update history table
CS50::query("INSERT INTO history (user_id,sold,sold_number,selling_price,date) VALUES(?,?,?,?,NOW() )",$_SESSION["id"],$_POST["symbol"],$selling_stock["shares"],$selling_price["price"]); 

but it shows a weird error:

**Fatal error: Unknown column 'user_id' in 'where clause' in /home/ubuntu/workspace/pset7/vendor/library50-php-5/CS50/CS50.php on line 352**

Although a similar query works just fine in buy.php . I also looked at the file specified in the error but there is nothing there. My history table has the following columns:enter image description here

0

Is there a column that has the exact name user_id in the history table? I suspect there isn't. If there is a user id column, I suspect that it has a slightly different name. It needs to be an exact match.

If this isn't the issue, please edit the question and add the full definition of the history table.

[EDIT: response to comment] I would suggest that you test your query in myphpadmin and see if it works there first. It's possible that the error you are currently getting may be misleading. My concern here is that you are adding 5 values when there are 9 columns and none of them allow for null and have no default values.

I'd also suggest a restructuring of the history table. Instead of essentially 3 columns for bought and 3 columns for sold, maybe have only symbol, number, price, and a field for bought/sold. It seems that with the current structure, 3 fields will be populated while the other 3 fields would be left blank - a bit wasteful. It would also eliminate the need for leaving any fields in a given row blank.

3
  • I think the naming is not the problem. I have added the complete structure of my history table. Please have a look at it again. -@Cliff Dec 2 '16 at 7:01
  • See my updated answer.
    – Cliff B
    Dec 2 '16 at 7:28
  • You were correct! there was a problem in my sql query which i found out in phpmydmin and few others related to associative arrays which I still don't understand. Thanks for your help !!. -@Cliff Dec 2 '16 at 10:32

You must log in to answer this question.

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