Best way to not update empty posts
- by user1533106
Hello,
Im using codeigniter, and the page in case just update infos about
an user. If the user go to the page and edit values and that posts
come as "" or empty (samething) then no update it let the query pass
it, i got a logic but its a bit ugly and ill take alot of time.
$nome = "'nome' =>" . $this->input->post('nome') . "'";
$sobrenome = "'sobrenome' =>" . $this->input->post('sobrenome') . "'";
if($nome != ""){
$nome = "'nome' =>" . $this->input->post('nome') . "'";
}else{
$nome = "";
}
if($sobrenome != ""){
$sobrenome = "'sobrenome' =>" . $this->input->post('sobrenome') . "'";
}else{
$sobrenome = "";
} $data = array($nome, $sobrenome);
The problem is, i got alot of fields :(
If anyone know a smart way or a better way, please i want know