|
Help a newbie with SQL errors!
04-13-2010, 09:15 AM
|
Help a newbie with SQL errors!
|
Posts: 87
|
This is so frustrating! Please help an sql newbie!  When I run this query...
Quote:
mysql_query("INSERT INTO cms_list
(title, htmltitle, name, day, month, year, blurb, cat1, cat2) VALUES ('$title', '$htmltitle', '$filename', '$day', '$month', '$year', '$blurb', '$cat1', '$cat2') ")
or die(mysql_error());
|
everything's just dandy... but when I run this query...
Quote:
mysql_query("INSERT INTO cms_list
(title, htmltitle, name, day, month, year, blurb, cat1, cat2, desc, keywords, content) VALUES ('$title', '$htmltitle', '$filename', '$day', '$month', '$year', '$blurb', '$cat1', '$cat2', '$desc', '$keywords', '$content') ")
or die(mysql_error());
|
I get an error! Why is that? Is there a query limit? all the fields are VARCHAR except 'content' which is TEXT...
Also, I realized why perhaps I've been having errors. Having commas in the text being inserted into the database should not produce errors, should it? I mean, inserting "haha, boo, funny" into 'keywords' shouldn't produce an error should it?
Thanks everybody!
__________________
Please login or register to view this content. Registration is FREE - The most comprehensive online resource for students and educators.
|
|
|
|
04-13-2010, 10:21 AM
|
Re: Help a newbie with SQL errors!
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Your problem is that you use a reserved word as a column name
Quote:
mysql_query("INSERT INTO cms_list
(title, htmltitle, name, day, month, year, blurb, cat1, cat2, desc, keywords, content) VALUES ('$title', '$htmltitle', '$filename', '$day', '$month', '$year', '$blurb', '$cat1', '$cat2', '$desc', '$keywords', '$content') ")
or die(mysql_error());
|
You must escape them with a backtick character `, to tell mysql that you are using a column name, and not a keyword
Quote:
mysql_query("INSERT INTO cms_list
(title, htmltitle, name, day, month, year, blurb, cat1, cat2, `desc`, keywords, content) VALUES ('$title', '$htmltitle', '$filename', '$day', '$month', '$year', '$blurb', '$cat1', '$cat2', '$desc', '$keywords', '$content') ")
or die(mysql_error());
|
http://dev.mysql.com/doc/refman/5.1/...ved-words.html
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
|
« Reply to Help a newbie with SQL errors!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|