iSE Posted April 20, 2010 Share Posted April 20, 2010 Ok, so fairly typical scenario... I have a form whereby the user can update both their membership and vehicle details in one form. Sometimes, the user will only make changes to their membership but not to their vehicle details. When performing an update, if there is no change to the details, the update statement will affect 0 rows even though it submitted successfully. Since for execution statements, my script checks against the number of rows affected as to whether it was successful or not, my entire site is throwing an error and undoing the previous changes as it thinks some weren't completed successfully. One option I've thought of would be to simply check for an error to report the success of an execution statement (INSERT, UPDATE, DELETE). However, I'm not entirely convinced this would be fool proof. Since this seems a fairly common thing to go through, I'm just wondering how people have gotten round this? In the past I've checked every detail against a SELECT statement and updated individual fields. This seems a huge overhead and I'm thinking there must be a better way. Thanks, iSE Quote Link to comment https://forums.phpfreaks.com/topic/199157-mysql-update-returns-0-on-no-change-obviously/ Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 $result = mysql_query('...'); if ($result) echo 'success'; else echo 'fail'; Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/199157-mysql-update-returns-0-on-no-change-obviously/#findComment-1045307 Share on other sites More sharing options...
iSE Posted April 21, 2010 Author Share Posted April 21, 2010 Not really considering I'm using the MySQLi extension and prepared statements. Something I obviously should have stated... Quote Link to comment https://forums.phpfreaks.com/topic/199157-mysql-update-returns-0-on-no-change-obviously/#findComment-1045638 Share on other sites More sharing options...
iSE Posted April 21, 2010 Author Share Posted April 21, 2010 On another look through the documentation, I must have misread it the first time, because I can just use mysqli_stmt::execute to return success or failure. So your sarcastic remark actually helped me double check. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/199157-mysql-update-returns-0-on-no-change-obviously/#findComment-1045641 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.