2

I keep getting "Duplicate entry '0' for key 'PRIMARY'" when running the following SQL command from a PHP script:

INSERT INTO Backgrounds (user, url)
VALUES ('$user', '$bgrequest')

And here is the code that generates the table below. The first insert works, but all subsequent requests do not. I have tried deleting the table and recreating, still no luck. Also when I insert a row from phpmyadmin, it works and increments without issue. For some reason it just doesn't seem to autoincrement when running the command from a PHP script...

CREATE TABLE  `freestylefriday`.`Backgrounds` (  
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,  
`user` VARCHAR( 255 ) NOT NULL ,  
`url` VARCHAR( 1000 ) NOT NULL  
) ENGINE = MYISAM  

Such a simple table and request... driving me crazy.

Treestyle
  • 41
  • 4
  • Possible duplicate of [MySQL 1062 - Duplicate entry '0' for key 'PRIMARY'](http://stackoverflow.com/questions/12179770/mysql-1062-duplicate-entry-0-for-key-primary) – Wes Foster Feb 17 '16 at 02:38
  • have you tried to create the table the old way? ... CREATE TABLE `freestylefriday`.`Backgrounds` ( id int NOT NULL AUTO_INCREMENT, `user` VARCHAR( 255 ) NOT NULL , `url` VARCHAR( 1000 ) NOT NULL PRIMARY KEY (id) ) – Ed Baker Feb 17 '16 at 03:19
  • Thanks Ed, that did the trick! – Treestyle Feb 18 '16 at 01:49

0 Answers0