markvaughn2006 Posted October 2, 2009 Share Posted October 2, 2009 I know this has to be easy, but I am having trouble figuring out how to make this insert into the next empty row... The primary key is a not null auto increment integer, so I don't want to have to enter the value for that. mysql_query("INSERT INTO events (type, from, to) VALUES('sale', '$you', '$me' ) ") any help?? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2009 Share Posted October 2, 2009 Both from and to are mysql reserved keywords - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html If you were using mysql_error() to troubleshoot why your query is failing, you would be getting sql syntax errors at those keywords where they are being used as column names. You should rename your columns to something else. Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-928841 Share on other sites More sharing options...
markvaughn2006 Posted October 2, 2009 Author Share Posted October 2, 2009 thats good to know! but thats not what is causing this error, i tried different columns also, this is the error... Duplicate entry '0' for key 1 Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-928845 Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2009 Share Posted October 2, 2009 One of the columns you are inserting must be defined as a key and you are attempting to insert a value that already exists. Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-928847 Share on other sites More sharing options...
Kieran Menor Posted October 2, 2009 Share Posted October 2, 2009 Did you forget to enable auto_increment fo your primary key column? Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-928987 Share on other sites More sharing options...
markvaughn2006 Posted October 2, 2009 Author Share Posted October 2, 2009 nope Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929060 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 Any chance we can see the output of ... SHOW COLUMNS FROM `events` Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929179 Share on other sites More sharing options...
markvaughn2006 Posted October 2, 2009 Author Share Posted October 2, 2009 the columns for my events table are (id, type, from, to, time) my intended command is... <?php mysql_query("INSERT INTO events (type, from, to, time) VALUES('$type', '$from', '$to', '$time' ) ") or die(mysql_error()); ?> and the error is... Duplicate entry '0' for key 1 I don't want to have to define the "id" field since it is the primary key, not null, auto incrementing field. Do I have to do some kind of 'count' command and add 1 to the highest number in the 'id' column and then insert some kind of $nextid variable that is the higest id+1?? Thanks for any help, I didn't really think this would be stumping me like this... Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929326 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 No you shouldn't have to. If you have PHPMyAdmin, can you just paste SHOW COLUMNS FROM `events` in the SQL box and check/show us the output. If your certain that id has auto increment set, then it sound like one of the other fields is also set to be a key of some kind. Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929330 Share on other sites More sharing options...
markvaughn2006 Posted October 2, 2009 Author Share Posted October 2, 2009 omg i'm an idiot...auto increment was not set. Sorry for wasting your time and thanks for helping me...lol Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929361 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 lol, happens to us all, at least it's solved. Quote Link to comment https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/#findComment-929365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.