Best way to not update empty posts
Posted
by
user1533106
on Stack Overflow
See other posts from Stack Overflow
or by user1533106
Published on 2014-06-05T14:49:27Z
Indexed on
2014/06/05
15:25 UTC
Read the original article
Hit count: 174
php
|codeigniter
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
© Stack Overflow or respective owner