Input.php - _fetch_from_array #699

Closed
anytimanywhere opened this Issue Nov 23, 2011 · 4 comments

Comments

Projects
None yet
4 participants

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 :

<?php

class MY_Input extends CI_Input
{
        function __construct()
        {
                parent::__construct();
        }

        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.

Thanks flashover:

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

ski1204 commented Apr 24, 2012

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 = "test_email@testing.com"; //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 = 'test_email@testing.com' WHERE users_email = 0
(this updates every users' email address with "test_email@testing.com")

If you apply that change, this is what the query will look like:
UPDATE USERS_USERS SET users_email = 'test_email@testing.com' WHERE users_email = NULL
(this does nothing)

Contributor

narfbg commented May 24, 2012

narfbg closed this May 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment