You have an error in your SQL syntax - near 'left) - php

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();

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

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

$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)";

left is a mysql reserved word. So you have to rename the column left.
See here : reserved Words for furhter information

Related

Error in PHP MySQL

I am trying to do a simple INSERT, but I keep on getting 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 'FROM,TO,ID,CURRENCY1,CURRENCY2,AMOUNT,NOTE,RATE) VALUES('test', 'test2', 'dd', '' at line 2
Here is my code:
mysql_query("INSERT INTO WIRET
(FROM,TO,ID,CURRENCY1,CURRENCY2,AMOUNT,NOTE,RATE) VALUES('$from', '$to', '$ID', '$currency1', '$currency2', '$amount','$note', '$rate') ")
or die(mysql_error());
Why am I getting this error? I copied this script from another area of my site where it works, I just changed the values.
FROM is a reserved word in MySQL (and SQL in general). If you really have a column named FROM you should wrap it with ` (backticks) so the parser knows you mean a name:
INSERT INTO WIRET (`FROM`, TO, ID, CURRENCY1, ...
If your column is named from you have to put it into "`" (backticks) because FROM is also a SQL keyword.
By putting a keyword (FROMhere) into backticks you say "this is not a SQL keyword" to the DBMS.
Example:
INSERT INTO WIRET (`FROM`,TO,ID,...

MySQL insert with multiple fields and where clause

I'm trying to construct a query for a cron that will run.
mysql_query("UPDATE `stocks` SET price='$pricez', open='$openz', high='$highz', low='$lowz', change='$changez', time='$times', percent='$percentz' WHERE symbol = '$symbolz' ");
The error I get is
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 'change='-0.10', time='1406050151', percent='-0.35%' WHERE symbol = 'ALMB.CO'' at line 1
Scavenged SOF and have yet to find a solution.
Reserved words just bit you:
Change is a reserved word thus needs to be escaped: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
mysql_query("UPDATE `stocks` SET price='$pricez', open='$openz', high='$highz',
low='$lowz', `change`='$changez', time='$times', percent='$percentz' WHERE symbol = '$symbolz' ");
So what is a reserved word?
They are words the engine uses to interpert specific requested commands. When these words are used as identifiers for tables or columns they must be treated in a specific manner usually escaping the words for the RDBMS involved.
Looks like you are using some reserved words for column names: Change and Time
You can escape these with backticks (`), or choose new coumn names
UPDATE `stocks`
SET `price`='$pricez',
`open`='$openz',
`high`='$highz',
`low`='$lowz',
`change`='$changez',
`time`='$times',
`percent`='$percentz'
WHERE symbol = '$symbolz'

Php mysqli->real_escape_string and MYSQL

I've a little question.
I've written this code to add the values to mysql database but when i run the code and I got an error. Can anybody help me?
the code:
$fel = $mysqli->query("INSERT INTO deleted (uid,buy_type,prop_type,district,street,room_min,room_max,price_min,price_max,condition_type,heat_type,lift_type,parking_type,type_of_del,when)
VALUES ('".$mysqli->real_escape_string($letomb['uid'])."',
'".$mysqli->real_escape_string($letomb['buy_type'])."',
'".$mysqli->real_escape_string($letomb['prop_type'])."',
'".$mysqli->real_escape_string($letomb['district'])."',
'".$mysqli->real_escape_string($letomb['street'])."',
'".$mysqli->real_escape_string($letomb['room_min'])."',
'".$mysqli->real_escape_string($letomb['room_max'])."',
'".$mysqli->real_escape_string($letomb['price_min'])."',
'".$mysqli->real_escape_string($letomb['price_max'])."',
'".$mysqli->real_escape_string($letomb['condition_type'])."',
'".$mysqli->real_escape_string($letomb['heat_type'])."',
'".$mysqli->real_escape_string($letomb['lift_type'])."',
'".$mysqli->real_escape_string($letomb['parking_type']).",
'".$mysqli->real_escape_string($type_of_del)."',
now())") or die($mysqli->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 'when) VALUES ('3', 'kiado', 'lakas', '1'' at line 1
WHEN is a reserved word. Enclosing it in backticks should fix your problem, as it will then be treated as an identifier.
`when`
You should use backticks around your column names. when is a MySQL keyword so it's being interpreted incorrectly. At the very least use backticks around when.

What's wrong with this sql code?

If I remove the line condition=\''.$this->condition.'\', it works.
If I let it there, the following error message appears:
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 'condition='unknown', promotional='0', website='0', quantity='1',
' at line 7
mysql_query('UPDATE products SET
name = \''.$this->name.'\',
description = \''.$this->description.'\',
brand = \''.$this->brand.'\',
model = \''.$this->model.'\',
price=\''.$this->price.'\',
condition=\''.$this->condition.'\',
promotional=\''.$this->promotional.'\',
website=\''.$this->website.'\',
quantity=\''.$this->quantity.'\',
service=\''.$this->service.'\'
WHERE id = \''.$this->id.'\' '
CONDITION is a reserved mysql keyword. You must enclose it in backticks:
`condition`=\''.$this->condition.'\',
You have to rename condition column. See Reserved MySQL keywords table

MySQL INSERT error

I got this error :
Database problem occur, please try again later.
- Error in query: INSERT INTO main SET title ='', url='www.jerseymurah.com', kod='jerseymurah', owner='Hasbul Aqill', tag='jersey, football, world cup', since='Feb 2010', desc='ssfsfsfsfs'
- 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 'desc='ssfsfsfsfs'' at line 1 (Error #1064)
- File: /home/yosh/domains/yosh.my/public_html/demo/admincp/tambah-save.php
and this is my mysql query code :
$query = "INSERT INTO main SET title ='".$ttile."', url='".$url."',
kod='".$kod."', owner='".$owner."', tag='".$tag."', since='".$since."',
desc='".$desc."'";
$db->rq($query);
Please help and thanks a lot!
DESC is a reserved word in mySQL.
You need to put that field in backticks:
`desc`="..."
maybe consider renaming the field.
mySQL reserved words in the manual
I think DESC is a reserved word, try escaping it with backticks.
mysql_query("INSERT INTO main(title,url,kod,owner,tag,since,description) VALUES('$title','$url','$kod','$owner','$tag','$since','$desc')");

Categories