MySQL Error

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
chizeng
Forum Newbie
Posts: 11
Joined: Sun Feb 28, 2010 10:52 pm

MySQL Error

Post by chizeng »

Hello everyone,

I am receiving this error while developing a PhP/MySQL application:

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 ''id', 'pointkey', 'ptop', 'pleft', 'pOrder', 'mapKey', 'userName', 'title', 'des' at line 1

Here's the full query:

Code: Select all

mysql_query("INSERT INTO points ('id', 'pointkey', 'ptop', 'pleft', 'pOrder', 'mapKey', 'userName', 'title', 'description', 'more') VALUES (NULL ,  '$gKey',  '',  '',  '',  '$mapKey',  '$userName',  'New Point',  '','');") or die(mysql_error());
The $-signed variables I am pretty clear that I have already set. Any kind help from board members would be greatly appreciated. Thanks,


Chi
w1n78
Forum Newbie
Posts: 12
Joined: Mon Mar 08, 2010 10:55 pm

Re: MySQL Error

Post by w1n78 »

don't use single quotes when listing columns

Code: Select all

 
mysql_query("INSERT INTO points (id, pointkey, ptop, pleft, pOrder, mapKey, userName, title, description, more) VALUES (NULL ,  '$gKey',  '',  '',  '',  '$mapKey',  '$userName',  'New Point',  '','');") or die(mysql_error());
 
chizeng
Forum Newbie
Posts: 11
Joined: Sun Feb 28, 2010 10:52 pm

Re: MySQL Error

Post by chizeng »

Thanks!
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: MySQL Error

Post by flying_circus »

w1n78 wrote:don't use single quotes when listing columns

Code: Select all

 
mysql_query("INSERT INTO points (id, pointkey, ptop, pleft, pOrder, mapKey, userName, title, description, more) VALUES (NULL ,  '$gKey',  '',  '',  '',  '$mapKey',  '$userName',  'New Point',  '','');") or die(mysql_error());
 
You should use back-ticks ( ` ) instead. :)

Code: Select all

 
mysql_query("INSERT INTO `points` (`id`, `pointkey`, `ptop`, `pleft`, `pOrder`, `mapKey`, `userName`, `title`, `description`, `more`) VALUES (NULL ,  '$gKey',  '',  '',  '',  '$mapKey',  '$userName',  'New Point',  '','');") or die(mysql_error());
 
Post Reply