What's wrong with this sql code? - php

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

Related

MySQL - how to match JSON string in where condition?

I am using MySQL 5.6 , one of my table field contains JSON data. I am getting syntax error when using below query -
SELECT * FROM products WHERE device_id = '1212'and product_id = '54'and option = '"{"229":"20"}"'
field option has value as {"229":"20"} I am getting following error -
#1064 - 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 'option = '"{"229":"20"}"'
LIMIT 0, 25' at line 1
Please suggest any solution , thanks much!!!
option is a reserved keyword in MySQL. Use backticks to escape it or choose a different name
... `option` = ...

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

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

PHP Error in MySQL Syntax

Here's the function I created:
function get_phurl_option($option) {
$db_result = mysql_query("SELECT value FROM ".DB_PREFIX."options WHERE option = '$option'") or db_die(__FILE__, __LINE__, mysql_error());
$db_row = mysql_fetch_row($db_result);
return $db_row[0];
}
However, upon visiting a page that uses the function, I get the following error:
File: /usr/home/<removed>/includes/functions.php
Line: 28
Message: 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 'option = 'shortcode_type'' at line 1
I'm not sure why this would be, I've tried apostrophes, speech marks, and backticks, neither of which seem to work. I can't figure out the problem here, so any help would be much appreciated.
option is a MySQL reserved word, so you need to enclose it in backticks
$db_result = mysql_query("SELECT value FROM ".DB_PREFIX."options WHERE `option` = '$option'")
The specified error usually means that the field you're attempting to access is invalid or reserved by MySQL. Make sure you escape all variables in backticks:
SELECT `value` FROM `".DB_PREFIX."options` WHERE `option` = '$option'

Inserting Metatag strings into a mysql table

I want to take meta tags from an external webpage and save it into my mysql db, although I keep getting an error. Some help would be appreciated.
$tags = get_meta_tags($_POST['url']);
if (array_key_exists("description", $tags)){
$desc = mysql_real_escape_string($tags['description']);
}
$postQ = mysql_query("INSERT INTO posts (userdesc,desc,title,url,userid) VALUES ('$userdesc','$desc','$title','$url','$userid')");
The error I keep getting is this: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,title,url,userid) VALUES ('Wow this house is small','We've featu' at line 1
desc is a mysql reserved word either enclose that field name in backticks or rename the field name to something else.
eg.
mysql_query("INSERT INTO posts (userdesc,`desc`,title,url,userid)...

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