I'm having one last hiccup with my implementation of history. Everything about it works just fine except for the fact that it appears that only one entry can be stored in my SQL table, permanently.

If the table is empty and I purchase or sell a stock then the information is stored correctly and outputs to my history page just like it should. However, if I make any other purchases or sales no new rows are added to the table. The original entry just stays there. If I delete that entry to buy or sell again then that new history log will be saved to the table but will also be the only one there. Any subsequent buys or sells aren't stored in the SQL table.

Why am I only able to input 1 row? I'm using the same SQL insert language that I've used for my other tables. Below is my code and table structure:

query("INSERT INTO history (id, transaction, date, symbol, shares, [![enter image description here][1]][1]price) VALUES(?, ?, now(), ?, ?, ?)", $id, $sell, $symbol, $shares, $price);

SQL Table Structure Screen Grab

2 Answers 2


I was typing that answer while you were posting. In short, you created a primary index on user id. The effect of this is to tell the table that only one entry with that ID is allowed. You could still add transactions for other id's, but only one each.

An index is still useful though. If you set up your column and index to non-unique and non-primary, then you can add all you want to the table. Also, given the size of this exercise (i.e., not a production database with thousands of transactions), an index isn't really needed because the impact on performance would be negligible.


Nevermind. I figured out the problem. For some reason I set user id to primary which locked out any future inserts to the table from the same user.

You must log in to answer this question.

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