Sometimes I just frustrate myself
Have you ever spent way too much time looking for a solution to a problem? Ever felt like smacking yourself in the head when you finally found the fix? Well today I spent about half an hour trying to find out why a MySQL INSERT query wasn’t working.
I was working on a logging table for my photography forum. The first page shows a random image as a featured image and I needed a way to keep track of what images were being displayed and when. So I created a new table and added an insert query to fill in the data. But only one record was created. No matter how many times I reran the function, only the first record remained.
Turned out I had forgotten to set the id field as auto_incr and wasn’t inserting it as part of the query. Since it was primary key every time the insert query tried to run it failed because there was already a record with that primary key. Editing the field to set it to auto_incr and all was set.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.