when post (or get) data isn't exists
the method $this->input->post will return FALSE,
when we insert data to database, it will be convert to 0
but we expect insert data to database the value is empty or NULL
so this function _fetch_from_array could return empty value or NULL
Put this in your /application/core/
File: MY_Input.php :
class MY_Input extends CI_Input
function post($key, $xss_clean = FALSE)
$post = parent::post($key, $xss_clean);
return ($post !== FALSE) ? $post : NULL;
It will now return NULL if it would normally return FALSE.
I know that...
I think put that in core library is better than extend it..
when we get data from url or form, var type always be [string]
if this function returns two type, sometimes it will make programer confuse
I would like to see that core change as a standard when installing CodeIgnitor. This is why:
If for some reason our post data doesn't exist, and we don't check for the post to be TRUE.
AND we will be using that data (FALSE or 0) in a table for the WHERE clause, it will update all records with whatever change you set.
Here is an example:
$old_email = $this->input->post('jibberish',true);
$new_email = "firstname.lastname@example.org"; //usually another post
$this->write_db->where('users_email', $old_email)->update('USERS_USERS', array(
'users_email' => $new_email,
UPDATE USERS_USERS SET users_email = 'email@example.com' WHERE users_email = 0
(this updates every users' email address with "firstname.lastname@example.org")
If you apply that change, this is what the query will look like:
UPDATE USERS_USERS SET users_email = 'email@example.com' WHERE users_email = NULL
(this does nothing)