Welcome Guest, Not a member yet? Register   Sign In
Need help with insert and htmlspecialchars


I am new to CodeIgniter and PHP classes. I like what I have seen of CodeIgniter and in an attempt to learn how it works I have been developing a few small personal projects. My latest project is a snippet database to store my coding snippets and I have run into a problem when inserting the code into the database.

To insert the code I have the following in the controller:

function addSnippet()
    $now = date('Y-m-d H:i:s');
    $data = array(
        'title' => $this->input->post('title'),
        'description' => $this->input->post('description'),
        'code' => $this->input->post('code'),
        'dateAdded' => $now,
        'catID' => $this->input->post('cat')

In the model I have the following:

Quote:function add_snippet($data)
$this->db->set('title', $data['title']);
$this->db->set('description', $data['description']);
$this->db->set('code', $data['code']);
$this->db->set('dateAdded', $data['dateAdded']);

$codeID = $this->db->insert_id();

$this->db->set('catID', $data['catID']);
$this->db->set('codeID', $codeID);


The problem is that when the script runs it appears to be applying htmlspecialchars to the data before it is inserted into the database so the PHP tags etc come out as <?php.

I would rather htmlspecialchars is applied before printing the data to a web page. How do I stop htmlspecialchars from being applied before it is inserted into the database?

Thank you for any help.

It looks like I have found the solution.

For anyone who comes across this problem too, it was due to having global_xss_filtering set to true. I have set this to false and things work as expected.

Shouldn't htmlspecialchars only be applied when outputting the data to a web page and other ways used to sanitize user inputs?

Theme © iAndrew 2016 - Forum software by © MyBB