By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,971 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,971 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
column.

Here is the stripped down code which causes the problem:
$queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id =
388";
$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!

Thanks,
Mark

Mar 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 08 Mar 2006 22:39:16 -0800, mark wrote:
$queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id = 388";


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

Cheers,
Andy
--
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

Mar 9 '06 #2

P: n/a
Andy,

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 =
388";

Thanks for the good eye! ;)

Mar 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.