Anyone knows where to look for? I just truncate the mysql table i am using so no id's are set. Also the ID is set to BIGINT(20), still i get Duplicate entry '1-22' for key 1 error Any suggestions?
Can you please provide table structure and your statement (probably INSERT or UPDATE) which causes the error. Regards
hi koko5, here's my insert query $sql = "INSERT INTO `wp_postsTest` ( `ID` , `post_author` , `post_date` , `post_date_gmt` , `post_content` , `post_title` , `post_category` , `post_excerpt` , `post_status` , `comment_status` , `ping_status` , `post_password` , `post_name` , `to_ping` , `pinged` , `post_modified` , `post_modified_gmt` , `post_content_filtered` , `post_parent` , `guid` , `menu_order` , `post_type` , `post_mime_type` , `comment_count` ) VALUES (NULL , '$post_author', '$post_date', '0000-00-00 00:00:00', '$post_content', '$post_title', '0', '', 'publish', 'open', 'open', '', '$post_name', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', 'post', '', '0')"; PHP:
Hi, 123GoToAndPlay, Using which one query you did erase all data from table: TRUNCATE or DELETE? You can prevent errors using REPLACE instead INSERT in your query but it's not clear solution about this error. Regards Edit: I mean truncate is best for erasing all data. So run truncate if you previous run delete and let's check is there any error during Insert.
hmm i use phpmyadmin to empty/truncate all data in wp_postsTest. So your suggestion is to query DELETE FROM wp_postsTest I thought both would be the same as the table will be empty
No, I suggest you use truncate via console or phpmyadmin query window because truncate resets auto_increment fileds but delete doesn't. You didn't provide table structure but did you run one select query to check is there any data left in table after this manual deletion which can cause such error? Just run truncate and try your query without modifications and let me know the result. Regards
tx, for the effort so far i truncate the table and i used my original insert query. again i get the Duplicate entry '1-22' for key 1 error i do have this query in a php for loop. What is the way to check if a table is really "clean/empty"?? Or should i just export the table structure and delete the table and create a new one?
You can check is table empty by query like this: SELECT EXISTS(SELECT * FROM wp_postsTest); Code (markup): or SELECT COUNT(*) FROM wp_postsTest; Code (markup): It can be error either during php loop or MyISAM broken table. You can check by using REPLACE instead INSERT in your query (other code is untouched; only replace words INSERT by REPLACE) and check how much records were Inserted during loop (if lower than expected than loop generated same values that are overwritten OR MyISAM table is broken and it's better to drop&create it); and are there any errors. Hope it helps.Regards Edit: If when using replace duplicate error occurs it is broken table I guess.
@siteTalkZone, yes the ID field is set to auto increment @koko5, done all your suggestions without any succes . I even drop and create the table Now i am trying to use simple contents for my $vars like "test" and "1234" and see what happens AHA, this looks to run good so it has to do with my $var contents. It's a extern product feed which i parse and i use addslashes to prevent quotes. But the auto increment column is NULL so duplicate entry shouldn't occur, right?? Which function should i use to prevent the duplicat entry error
It's better using mysql_real_escape_string instead addslashes. You can omit ID and NULL : $sql = "INSERT INTO `wp_postsTest` (`post_author` , `post_date` , `post_date_gmt` , `post_content` , `post_title` , `post_category` , `post_excerpt` , `post_status` , `comment_status` , `ping_status` , `post_password` , `post_name` , `to_ping` , `pinged` , `post_modified` , `post_modified_gmt` , `post_content_filtered` , `post_parent` , `guid` , `menu_order` , `post_type` , `post_mime_type` , `comment_count` ) VALUES ('$post_author', '$post_date', '0000-00-00 00:00:00', '$post_content', '$post_title', '0', '', 'publish', 'open', 'open', '', '$post_name', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', 'post', '', '0')"; PHP: You can echo $sql instead of executing queries in the loop and then copy&paste each query into phpmyadmin and check why and where error occurs.