You have an error in your SQL syntax;

Reply

Join Date: Jul 2009
Posts: 27
Reputation: Toxikr3 is an unknown quantity at this point 
Solved Threads: 0
Toxikr3 Toxikr3 is offline Offline
Light Poster

You have an error in your SQL syntax;

 
0
  #1
Jul 14th, 2009
Hi guys, I was trying to implement a friends script but I encountered this error


Error: 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 'by) VALUES ('Toxikr3' , 'moderator')' at line 1

I tried to insert values Toxikr3 and moderator in the columns username and by

It inserts fine when there is only one thing to insert, but gives me error when I insert more then one.

My Code:
  1. $query = ("INSERT INTO friendrequest (username,by) VALUES ('$_GET[user]' , '$by')"); //inserts the request
  2.  
  3. if (!mysql_query($query))
  4. {
  5. die('Error: ' . mysql_error());
  6. }
  7. echo ( "$fusername $by has been sent a request you must now wait for it to be accepted" ); //echos completion
  8. }
  9. else {
  10. echo ( "No request was made" ); // or no request sent
  11. }
  12. }else {
  13. echo ( "You need to be logged in" ); //not logged in
  14. }
Please help, I just can't figure it out. If you require the top code, I will post it.
Last edited by Toxikr3; Jul 14th, 2009 at 11:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: You have an error in your SQL syntax;

 
0
  #2
Jul 15th, 2009
Originally Posted by Toxikr3 View Post
...Error: 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 'by) VALUES ('Toxikr3' , 'moderator')' at line 1
Re-read the quoted part above, then read the table of reserved words in the MySQL manual. (Hint: 'by' is a reserved word.)

While you can use reserved words if you quote them correctly, it is best to avoid using them where they can cause problems.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 793
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: You have an error in your SQL syntax;

 
0
  #3
Jul 15th, 2009
Change $_GET[user] to {$_GET['user']} (including the braces). An even better way would be:
  1. $user = $_GET['user'];
  2. if(strlen($user) == 0)
  3. {
  4. echo "No user";
  5. die;
  6. }
  7. $query = "INSERT INTO friendrequest (username,by) VALUES ('$user' , '$by')";
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Toxikr3 is an unknown quantity at this point 
Solved Threads: 0
Toxikr3 Toxikr3 is offline Offline
Light Poster

Re: You have an error in your SQL syntax;

 
0
  #4
Jul 15th, 2009
Thank you for your replys, I will try them out and hope it works.

-Toxikr3
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC