Jump to content

[SOLVED] Update query updates but does not update the database


centerwork

Recommended Posts

Here is my query.

 

$query = "UPDATE site_users SET site_users.su_f_name='$f_name', site_users.su_l_name='$l_name', site_users.su_user='$user',  site_users.su_priv='$priv' WHERE site_users.su_id = '$su_id'";
$insert_result = mysql_query($query) or die(mysql_error());

 

The $insert_result  returns 1 when it executes, however it does not actually update the information in the database. It also does not return any errors.

 

Any help would be appreciated.

if 'site_users' is the name of the table, and it's the only table you're using, don't use site_users.column_name. Just do the column name for example: site_users.su_f_name='$f_name' turns into su_f_name='$f_name'.

 

 

I'd also say make for sure that $su_id is set to the number it's supposed to be

The only thing I can't figure out is why the query was returning 1 row affected. When $su_id was not set.

 

$insert_result is the returned value from the mysql_query() statement. For an UPDATE, that will be a FALSE (0) or TRUE (1) value. A TRUE value just means that the query executed without any error. The value returned by mysql_query() is not the number of rows affected. To get the number of rows affected, you would need to use a mysql_affected_rows() statement.

 

For the case where the $su_id was not set, the WHERE clause was false (there were no matching rows.) $insert_result was TRUE because the query executed. mysql_affected_rows() would have returned a zero.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.