Jump to content

Checking Update Data If It Does Not Exist In The Database


50r

Recommended Posts

Hello freaks i have a problem here which is not so big but tricky though. i have a form with about 30 fields that i have to use to run a update to the database.

 

the form populates the existing data from the database when it is called. then what i want is i before fields are submited to database for update, all fields must be checked to see weather any is still the same as the exsting onein the database and if its found, the update on that field must not run it should move to the next field.

 

i know i can check one by one fields to see using the if and else but as fields are so many i am going to end up with a big banch of code. is there any simple way i can tackle this?

Link to comment
Share on other sites

...and you next problem is going to be to construct EVERY TIME a dynamic UPDATE based just on the columns that were modified... absolutely unnecessary and cumbersome, but just out of curiosity... why do you want to do that?.... maybe a better explanation could bring some light and more help to get your objectives in an alternative way

Link to comment
Share on other sites

...and you next problem is going to be to construct EVERY TIME a dynamic UPDATE based just on the columns that were modified...

 

not entirely true. You can foreach the $row array and compare it with the $_post array, if there is a match unset the $row element. Then do a foreach($row) to set a string with the keys ( field names ) and another string with the values which can also be achieved via implode(). Then just join the 2 strings in the UPDATE query. It is important that your $_POST and $row array keys are the same for your ease.

Edited by Manixat
Link to comment
Share on other sites

@manixat : what exactly is "not entirely true"?... you are explaining exactly the process that I mean... cumbersome .. overly complicated when in reality is not needed, a simple and direct UPDATE without care if an specific column has changed or not will do the same job ... just easily... granted the process that you described is the way to do it if the OP decide to go that route. But as I said by the end of my previous post, we need to know more about the OP objectives to determine if is justifiable or not.

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.