| | |
You have an error in your SQL syntax;
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2009
Posts: 27
Reputation:
Solved Threads: 0
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: Please help, I just can't figure it out. If you require the top code, I will post it.
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:
PHP Syntax (Toggle Plain Text)
$query = ("INSERT INTO friendrequest (username,by) VALUES ('$_GET[user]' , '$by')"); //inserts the request if (!mysql_query($query)) { die('Error: ' . mysql_error()); } echo ( "$fusername $by has been sent a request you must now wait for it to be accepted" ); //echos completion } else { echo ( "No request was made" ); // or no request sent } }else { echo ( "You need to be logged in" ); //not logged in }
Last edited by Toxikr3; Jul 14th, 2009 at 11:16 pm.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
...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
While you can use reserved words if you quote them correctly, it is best to avoid using them where they can cause problems.
Change $_GET[user] to {$_GET['user']} (including the braces). An even better way would be:
php Syntax (Toggle Plain Text)
$user = $_GET['user']; if(strlen($user) == 0) { echo "No user"; die; } $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. ![]() |
Similar Threads
- SQL Syntax Error (MySQL)
- MySQL/PHP UPDATE Syntax error (MySQL)
- syntax error.... (MySQL)
- MySQL syntax error check for the right syntax to use near 'A (A) )' at line 1 (PHP)
- UPDATE syntax error (MySQL)
- Error "Syntax" (Windows 95 / 98 / Me)
Other Threads in the PHP Forum
- Previous Thread: .htaccess (url rewriting)
- Next Thread: basename($_SERVER["REQUEST_URI"])
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





