Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Help a newbie with SQL errors!
Old 04-13-2010, 09:15 AM Help a newbie with SQL errors!
Skilled Talker

Posts: 87
Trades: 0
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.
yuechen is offline
Reply With Quote
View Public Profile Visit yuechen's homepage!
 
 
Register now for full access!
Old 04-13-2010, 10:21 AM Re: Help a newbie with SQL errors!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Help a newbie with SQL errors!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14594 seconds with 12 queries