Jump to content

MySQL UPDATE returns 0 on no change... obviously!


iSE

Recommended Posts

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

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.