|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26855 UPDATE query unexplicable behavior
Submitted: 2004-01-09 13:44 UTC Modified: 2004-01-09 14:04 UTC
From: superzouz at hotmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.4 OS: various
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
9 + 4 = ?
Subscribe to this entry?

 [2004-01-09 13:44 UTC] superzouz at hotmail dot com
When I run the following query through PHP:
UPDATE config_intranet SET confvalue = '' WHERE confkey 'vpn_server_ip'  
I get the following error.
1064: You have an error in your SQL syntax near 'query' at line 1

But if I type the same query directly into MySQL, it is executed correctly!

I was able to reproduce this situation on my PC (Windows XP SP1) with PHP 4.3.4 and MySQL "client api version 3.23.49", and on 2 internet hosting providers running PHP 4.x with mySql on *nix systems, so it is not an issue with my configuration.

There is nothing in the official PHP docs stating that a query would be handled differently by PHP and MySQL.


Reproduce code:
$conn = mysql_connect ( "localhost", "rolfen" , "" );
mysql_select_db("dergham", $conn);
$query = mysql_real_escape_string("UPDATE config_intranet SET confvalue = ''  WHERE confkey = 'vpn_server_ip'");
$res = mysql_query(query, $conn);

		if ($res)
			echo "success";
		else {
			die("Error while updating config table. Error Output: <br/>". mysql_errno() . ": " . mysql_error(). "<br/>"."Query follows:<br/>".$query);
			return False;

Expected result:

Actual result:
Content-type: text/html

X-Powered-By: PHP/4.3.2

X-Powered-By: PHP/4.3.2

Content-type: text/html

Error while updating config table. Error Output: <br/>1064: You have an error in your SQL syntax near 'query' at line 1<br/>Query follows:<br/>UPDATE config_intranet SET confvalue = \'\'  WHERE confkey = \'vpn_server_ip\'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-09 14:04 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

You see the \\\' in the error message? That\'s why.


 [2004-05-12 10:05 UTC] bugs dot php dot net at emailfilter dot de
You can't use mysql_real_escape_string() for the full query. The correct way would be:
$query = "UPDATE config_intranet SET confvalue = '" . mysql_real_escape_string('' ) . "' WHERE confkey = '" . mysql_real_escape_string('vpn_server_ip') . "'";
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Dec 10 21:01:28 2023 UTC