User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 427,804 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,789 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 2475 | Replies: 6
Reply
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

MySQL INSERT not working. Why?

  #1  
Jan 6th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: MySQL INSERT not working. Why?

  #2  
Jan 6th, 2007
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:
Last edited by nathanpacker : Jan 6th, 2007 at 1:32 am. Reason: misspelling
Reply With Quote  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: MySQL INSERT not working. Why?

  #3  
Jan 6th, 2007
Use backticks: `group`
Reply With Quote  
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: MySQL INSERT not working. Why?

  #4  
Jan 6th, 2007
Originally Posted by php_daemon View Post
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.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,222
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 935
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: MySQL INSERT not working. Why?

  #5  
Jan 6th, 2007
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.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: MySQL INSERT not working. Why?

  #6  
Jan 6th, 2007
Originally Posted by Ancient Dragon View Post
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.
Reply With Quote  
Join Date: Aug 2006
Posts: 10
Reputation: ad_rulz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
ad_rulz ad_rulz is offline Offline
Newbie Poster

Re: MySQL INSERT not working. Why?

  #7  
Jan 10th, 2007
Originally Posted by nathanpacker View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 2:18 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC