Jump to content

[SOLVED] INSERT INTO next row


markvaughn2006

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/176250-solved-insert-into-next-row/
Share on other sites

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.

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...

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.