Inserting post data |
[eluser]elmne[/eluser]
If i want to insert post data into the database but exclude empty fields (POSTS) that a user may not have filled in, how do i achieve that? Validation cannot stop this, as it checks only for values that are a must to fill in, but if teh user doesn't have to fill in things like all address fields and certain other fields, then these should not be input. How do i check each POST field within the model for this? I tried this below Code: if (!empty($this->input->post('title'))) { $this->title = $this->input->post('title'); } but I got this error message Quote:Fatal error: Can't use method return value in write context
[eluser]Armchair Samurai[/eluser]
RTM: empty() You can only use variables with empty() - anything else will throw an error. If you want to do this, maybe best to loop through the post array then remove anything that has no value. Alternately: Code: if ( ! empty($_POST['title'])) { $this->title = $this->input->post('title'); }
[eluser]vitoco[/eluser]
$this->input->post('index') return FALSE when the 'index' is not set... so Code: if (!is_bool($this->input->post('title'))) { $this->title = $this->input->post('title'); } Saludos
|
Welcome Guest, Not a member yet? Register Sign In |