[eluser]Unknown[/eluser]
Hi,
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:
Code:
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')
);
$this->code_model->add_snippet($data);
$this->index();
}
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']);
$this->db->insert('snippet');
$codeID = $this->db->insert_id();
$this->db->set('catID', $data['catID']);
$this->db->set('codeID', $codeID);
$this->db->insert('catSnippet');
return;
}
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.