Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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