Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
March 9, 2006, 6:39 am
rate this thread
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
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
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