CodeIgniter Forums
How to return an empty string instead of null for $this->input->post() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to return an empty string instead of null for $this->input->post() (/showthread.php?tid=1528)



How to return an empty string instead of null for $this->input->post() - eldan88 - 03-18-2015

Hey Guys,

As mentioned in the title, I want to return an empty string because mysql won't let me insert value as NULL. I tried making the following changes from this
PHP Code:
public function post($index NULL$xss_clean NULL)
    {
        return 
$this->_fetch_from_array($_POST$index$xss_clean);
    } 

to this
PHP Code:
public function post($index ""$xss_clean NULL)
    {
        return 
$this->_fetch_from_array($_POST$index$xss_clean);
    } 

But it still returns NULL. Any suggestions on how i can do that?


RE: How to return an empty string instead of null for $this->input->post() - eldan88 - 03-18-2015

Nevermind guys! I just figured to set the mysql column to NULL


RE: How to return an empty string instead of null for $this->input->post() - ivantcholakov - 03-18-2015

$the_string = (string) $this->input->post('the_string');