Update statement causes mysql varchar field to be set to empty string

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have come across a problem that has me baffled.

I am using PHP with MySQL 4.1.14. Whenever I execute an update
statement against a specific table, some of the varchar fields do not
get set to the new values, but get set to empty strings instead.

I have simplified the code down to updating a single column in the
table, but the same results happen when updating just the single

Here is the stripped down code which causes the problem:

$queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id =
$db = mysql_connect("hostname", "user", "pass");
mysql_select_db("CUSTOMER", $db) or die(mysql_error());
mysql_query($queryString, $db) or die(mysql_error());

Printing the query string after executing mysql_query shows the
following query:

UPDATE REGISTRATION SET passwd = 'test' WHERE id = 388

This query updates the column successfully when run directly through
phpMyAdmin. When run through PHP using the code above then column is
set to an empty string value.

There is no error returned if I call mysql_error() nor is there any
unusual info returned from mysql_info()  (other than it telling me that
1 row was affected).

Does anyone have any ideas what the underlying problem is on this one?
Could be an attribute of the database table or columns that would cause
this behavior? I have racked my brain for a while over this problem.

Any insight would be appreciated!


Re: Update statement causes mysql varchar field to be set to empty string

On Wed, 08 Mar 2006 22:39:16 -0800, mark wrote:
Quoted text here. Click to load it

Is it just a typo in your newsgroup post that you have two single quotes
after $pass or is that straight from the code?



Andy Jeffries MBCS CITP ZCE   | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Re: Update statement causes mysql varchar field to be set to empty string


I had a typo in my original post -- there is only a single quote after
the $pass variable.

The actual code is:

$queryString = "UPDATE REGISTRATION SET passwd = '$pass' WHERE id =

Thanks for the good eye! ;)

Site Timeline