![]() |
| ||
| 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 |
| ||
| 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: |
| ||
| Re: MySQL INSERT not working. Why? Use backticks: `group` |
| ||
| Re: MySQL INSERT not working. Why? Quote:
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. ;) |
| ||
| 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. |
| ||
| Re: MySQL INSERT not working. Why? Quote:
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. |
| ||
| Re: MySQL INSERT not working. Why? Quote:
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