centerwork Posted August 16, 2008 Share Posted August 16, 2008 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 https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/ Share on other sites More sharing options...
dannyb785 Posted August 16, 2008 Share Posted August 16, 2008 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 https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/#findComment-618114 Share on other sites More sharing options...
centerwork Posted August 16, 2008 Author Share Posted August 16, 2008 It was not the "site_users.column_name" it was that my form was not passing the '$su_id'. The only thing I can't figure out is why the query was returning 1 row affected. When $su_id was not set. Link to comment https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/#findComment-618143 Share on other sites More sharing options...
Hooker Posted August 16, 2008 Share Posted August 16, 2008 do you have a record with "su_id" as NULL or empty? Link to comment https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/#findComment-618211 Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2008 Share Posted August 17, 2008 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 https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/#findComment-618248 Share on other sites More sharing options...
centerwork Posted August 17, 2008 Author Share Posted August 17, 2008 Thank you, That is a very good explanation and will help me a lot with future coding. Thanks again. Link to comment https://forums.phpfreaks.com/topic/119997-solved-update-query-updates-but-does-not-update-the-database/#findComment-618254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.