SQL Update Query error dont know whats going wrong - php

SQL query:
UPDATE a2418693_GCM.driver SET lat = 78.54555,
LONG = 78.45544252 WHERE username = 'rakesh'
MySQL Message: Documentation
#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 'long=78.45544252 WHERE username='rakesh'' at line 2
Whats the problem here?
I am using the following query..
update a2418693_GCM.driver
SET lat=78.54555,long=78.45544252 WHERE username='rakesh'

It's giving you a syntax error because you are using a reserved MySQL keyword "long". To fix this, you need to either rename your column or escape it the "MySQL" way using backticks
UPDATE `a2418693_GCM`.`driver` SET
`lat` ='78.54555',
`long` ='78.45544252'
WHERE `username` ='rakesh'

UPDATE a2418693_GCM.driver SET lat = 78.54555,
longitude = 78.45544252 WHERE username = 'rakesh'
since long is a data type
so I used longitude in place of long

Related

How can I do a Update with slash on MySQL?

Hello I try do a Update like this
$sql = "UPDATE info SET YES/NO = '$_POST[value]' WHERE ID = '$_POST[id]'";
I am getting this error:
Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '/NO = 'YES' WHERE ID = '5'
I think this can be error from use SLASH on my database, If it is the problem how can i solve it?, thanks and i cant find any on google working for it.
Usualy, anything different than alphanumeric and underscore is not recommended.
Indeed, it is not a good practice to name a colomn like you did.
I will recommend you to rename the colomn yes_no otherwise, you will get the same error again, again and again.

unable to rectify error in database updation using php

I am trying to update my database with php and for that I have written the following query :
$query = " UPDATE users SET username = '$username' , password = '$password' WHERE id = $id ";
and the error is shown as :
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near '' at line 1
can you please help..
“syntax to use near ‘something’” shows the first few characters after the last part of the query that MySQL could parse. When ‘something’ is a zero-length string like in this case, it means the query ended before it was complete. That points to $id being an empty string.
You didn’t ask for comments on whether your query has other severe problems that will certainly lead to cybercreeps pwning your web site, so I won’t offer any such comments. :-)

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` = ...

Why is this following mySQL query failing?

I don't know why the following mySQL query keeps giving me the following 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 'http://some.url' at line 2
The SQL query itself is this:
DB_ExecuteQuery("UPDATE driver
SET windowsPhoneID = $uri
WHERE userID = $userID");
$userID is just the primary key of the table and is just a VARCHAR. I don't know why the $uri part isn't valid. WindowsPhoneID should be stored as TEXT, so there aren't any mismatched types or anything like that.
Any pointers?
You should add quotes around the parameters:
DB_ExecuteQuery("UPDATE driver
SET windowsPhoneID = '$uri'
WHERE userID = '$userID'");
Remark:
And like Mike gently suggested, please use PDO or MySQLi to prevent sql-injection.

Annoying mysql update query problem

I'm trying to update using mysql_query in php and it gives me 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 'read='1' WHERE id='14'' at line 1
I've been looking at my query for about 10 minutes now and I cant find whats wrong with it. Here it is:
if ($row['read'] == 0) {
mysql_query("UPDATE mail SET read='1' WHERE id='$mailid'") or die(mysql_error());
}
Do anyone see where the error is?
read is a reserved word.
Enclose it into the backticks:
UPDATE mail SET `read`='1' WHERE id='$mailid'
How about...
"UPDATE `mail` SET `read`='1' WHERE `id`='".$mailid."'"
read is a reserved word. You need to use backticks ` around read.

Categories