Jump to content

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


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

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  8)

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.