Welcome Guest, Not a member yet? Register   Sign In
Best practice for editing db data.
#1

My question is mainly for educational purposes, so..
What is the best practice for updating data in db only if they are not empty in form?

For example lets say i have a form in user's panel which contains his info (e.g. user email, name etc..)
The fields are fulfilled with parsing data in "value" attribute, but the password and some other fields are empty by default. 

What is the fastest way to pass them into an array only if they are not blank, in order not to change the already registered value in db?!

I hope my question is understandable.. if not, feel free to ask for clarification!

Thank you!!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply
#2

Personally I query the DB for that user profile to get a $user object.
And then I do something like this:
PHP Code:
// Do your validation here or in form_validation.
if( !empty($this->input->post('address') ) {
 
   $user->address $this->input->post('address');

After that I do an update query to the DB. And it "replaces" everything again with new and old data.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB