mysql insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

mysql insert

Post by ayfine »

Hey

I have no idea why this isn't working. The insert code is this

Code: Select all

$insert = mysql_query("INSERT into user_subs (title, desc, url, type, tags, date, author_id) values ('$title', '$final', '$url', 'story', '$tags', '$date', {$_SESSION['uid']})") or die(mysql_error());
This is the error I am getting when I submit

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, url, type, tags, date, author_id) values ('awesome', 'asdffff', 'http://ch' at line 1

Any idea whats wrong?
Last edited by ayfine on Sun Jul 08, 2007 7:32 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do you get an error message?
Please post the error message.
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Post by ayfine »

volka wrote:Do you get an error message?
Please post the error message.
Sorry

just edited it in.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

desc is a reserved word for mysql
http://dev.mysql.com/doc/refman/5.0/en/ ... words.html lists all(?) reserved words and tells you how you can use them as field identifiers (if you must).
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Post by ayfine »

volka wrote:desc is a reserved word for mysql
http://dev.mysql.com/doc/refman/5.0/en/ ... words.html lists all(?) reserved words and tells you how you can use them as field identifiers (if you must).
Thank you!

Added an r at the end and now everything's fine!
designerman
Forum Newbie
Posts: 4
Joined: Mon Jul 09, 2007 5:47 am

Post by designerman »

To get a good error message out of mysql its a good idea to use the mysql_error(); function eg

Code: Select all

$sql = "INSERT INTO table (colum1, colum2, colum3) VALUES ('foo', 'bar', 'foo')"; 
if(!mysql_query($sql)){
  echo 'Error in query! Mysql said: ". mysql_error();
  echo '<br />The query: '. $sql;
}
Using a class for running mysql queries will offer these features by default.
Post Reply