0

I'm a newbie in the php programming.

I would like to apply an insert query but I get this 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 'left) VALUES ('****df','****2135gh','***@yahoo.com' at line 2"}

$sql_insert_new_user = "insert into users (username,password,email,status,finance,province,city,address,tell,
mobile,admin_seen,type,left) VALUES ('$username','$password','$email',1,0,$town,$city,
'$address','$telephone','$mobile',0,'employe',0)";

            mysql_query($sql_insert_new_user);
            $error = mysql_error();
potashin
  • 43,297
  • 11
  • 81
  • 105
S.M_Emamian
  • 16,079
  • 27
  • 115
  • 222
  • 1
    Your code is vulnerable to [SQL injection](http://stackoverflow.com/q/60174/4193263). Prefer using Prepared Statements. – ByteHamster Apr 01 '15 at 09:01

4 Answers4

7

left is a reserved word and in the query you need escape with backtics

`left`

https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Abhik Chakraborty
  • 43,914
  • 5
  • 48
  • 61
  • 1
    ...or better, change the column name to something like `lft` –  Apr 01 '15 at 08:55
  • Yeah @HoboSapiens I agree but its really hard to maintain it since the reserved words will often may get added with every newer version of mysql. Once approach is to always back-tics the column name into the query so that any word I am using today if it becomes reserved tomorrow my query will not fail. – Abhik Chakraborty Apr 01 '15 at 08:58
0

left is a reserved word and in the query you need to use like this for all reserved word 'left'

This gives all the details about reserved word https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Rex Rex
  • 1,002
  • 8
  • 29
-1
$sql_insert_new_user = "insert into users (username,password,email,status,finance,province,city,address,tell,
mobile,admin_seen,type,`left`) VALUES ('$username','$password','$email',1,0,$town,$city,
'$address','$telephone','$mobile',0,'employe',0)";
Vivek Singh
  • 2,445
  • 1
  • 13
  • 26
-1

left is a mysql reserved word. So you have to rename the column left.

See here : reserved Words for furhter information

empiric
  • 7,665
  • 6
  • 39
  • 47
Akhil.p.p
  • 11
  • 4