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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.