Welcome Guest, Not a member yet? Register   Sign In
Retrieving data from db...fields have quotes around them.
#1

[eluser]CroNiX[/eluser]
For some reason, when I insert escaped data into the database and then later retrieve it, the data that was escaped has single quotes around it. Is this normal or am I doing something wrong?

Here is some stripped down code (not showing all fields as its irrelevant).
Controller:
Code:
function add()
{
    $data = array();
    $this->load->library('Form_validation');
    $this->load->library('global');
      
    $petitioner_id = $this->uri->segment(3);
      
    $val = $this->form_validation;
    $this->form_validation->set_error_delimiters('<div class="red">', '</div>');
        
    $val->set_rules('fname', 'First Name', 'trim|required|xss_clean');
        
    if ($val->run())
    {
        $field = array();
        $field['petitioner_id'] = $petitioner_id;
        $field['fname'] = $this->db->escape($this->input->post('fname'));
                        
        $success = $this->petitioner_model->add($field);
        $data['message'] = ($success == 1) ? 'Petitioner info saved.' : 'There was an error saving the petitioner info.';
    }
    $this->global->make_page('Add Petitioner Information', $this->load->view('backend/petitioners_view', $data, TRUE));
}

The model:
Code:
function add($data)
{
    return $this->db->insert('user_petitioner', $data);
}

An example of fname that gets stored in the database: 'bill' with the single quotes around it.

So what am I doing wrong with this?
Thanks.
#2

[eluser]Armchair Samurai[/eluser]
You're escaping things twice: once in your controller with $this->db->escape() and then again in the model with $this->db->insert().
#3

[eluser]pistolPete[/eluser]
User Guide - Inserting Data
Quote:Note: All values are escaped automatically producing safer queries.
#4

[eluser]CroNiX[/eluser]
Thanks guys.




Theme © iAndrew 2016 - Forum software by © MyBB