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
  • 44,205
  • 11
  • 83
  • 107
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • 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
  • 44,654
  • 6
  • 52
  • 63
  • 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,030
  • 1
  • 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,453
  • 1
  • 14
  • 27
-1

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

See here : reserved Words for furhter information

empiric
  • 7,825
  • 7
  • 37
  • 48
Akhil.p.p
  • 11
  • 4