DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   MySQL INSERT not working. Why? (http://www.daniweb.com/forums/thread66503.html)

nathanpacker Jan 6th, 2007 1:23 am
MySQL INSERT not working. Why?
 
Hey, I'm doing a simple INSERT command, can you tell me what's wrong with it? I won't bother you with the php right now, cause I'm simply trying to get it work in the MySQL command line. Here is the exact command:

INSERT INTO Birthdays(ID, firstname, lastname, birthday, group) VALUES('','Sam','Smith','June','Junior')

As far as I know, this is following syntax perfectly. But I get the following error:
http://www.packerworld.com/nate_personal/sql_error.JPG
Notice how "group", which should be a field in my table, is formatted in the query as if it's a command, instead of a field? I just don't get it!

Maybe I've set the fields in my table up incorrectly? I'm kind of new at MySQL, so maybe my table isn't set up correctly. Here's a screenshot of my table:
http://www.packerworld.com/nate_personal/table.JPG

nathanpacker Jan 6th, 2007 1:31 am
Re: MySQL INSERT not working. Why?
 
I tell you, I do this every time. I work for about an hour or so trying to figure out a problem, trying to exhaust all my resources before trying here, but without fail, as soon as I post here, I will, immediately after hitting the "submit post" button, solve the problem on my own.

Apparently, I shouldn't name one of my fields, "group"? I guess "group" is a command in the MySQL syntax, so it was getting confused. I changed the field name to something else, and it works great. So is this a rule I missed? Or is there a way to name a field "group" without it messing up like this?

Thanks anyway. :lol:

php_daemon Jan 6th, 2007 6:46 pm
Re: MySQL INSERT not working. Why?
 
Use backticks: `group`

nathanpacker Jan 6th, 2007 7:38 pm
Re: MySQL INSERT not working. Why?
 
Quote:

Originally Posted by php_daemon (Post 297904)
Use backticks: `group`


Thanks. I guess one of these days I'm going to have to take a course on PHP and MySQL rather than just trying to do it all off the cuff. ;)

Ancient Dragon Jan 6th, 2007 9:40 pm
Re: MySQL INSERT not working. Why?
 
The first field, ID, is an integer and does not allow null values but you are passing a blank string ''. I think you will probably get runtime errors on that.

nathanpacker Jan 6th, 2007 10:57 pm
Re: MySQL INSERT not working. Why?
 
Quote:

Originally Posted by Ancient Dragon (Post 297989)
The first field, ID, is an integer and does not allow null values but you are passing a blank string ''. I think you will probably get runtime errors on that.


Well, I guess I could do with out it, but I run several scripts like that and never get a run time error because of that. But I guess it is uneeded.

ad_rulz Jan 10th, 2007 8:23 am
Re: MySQL INSERT not working. Why?
 
Quote:

Originally Posted by nathanpacker (Post 297577)
Hey, I'm doing a simple INSERT command, can you tell me what's wrong with it? I won't bother you with the php right now, cause I'm simply trying to get it work in the MySQL command line. Here is the exact command:

INSERT INTO Birthdays(ID, firstname, lastname, birthday, group) VALUES('','Sam','Smith','June','Junior')

As far as I know, this is following syntax perfectly. But I get the following error:
http://www.packerworld.com/nate_personal/sql_error.JPG
Notice how "group", which should be a field in my table, is formatted in the query as if it's a command, instead of a field? I just don't get it!

Maybe I've set the fields in my table up incorrectly? I'm kind of new at MySQL, so maybe my table isn't set up correctly. Here's a screenshot of my table:
http://www.packerworld.com/nate_personal/table.JPG

Hi ,

I think if you do not mention the field that is auto_increment while inserting the data it should do. Because auto_increment will start generating value from 0 by default and hence it cannot be kept as NULL.

The following query might work for you.

[INSERT INTO Birthdays(firstname, lastname, birthday, group) VALUES('Sam','Smith','June','Junior');]

Cheers,
Adi.


All times are GMT -4. The time now is 9:15 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC