Reputation: 109
I have a form containing textbox and textarea. If I am going to input text(using my keyboard) even if it contains special characters, it produces an exact result depending on the input. However, when I "copied" sentence or paragraph from another website contact special charactes like single quote ('), double quotes returns inappropriate result.
example: Input1 single quote(') Output is ’ Input2 double quote("") output is €œ
Here is my code
//From my view.php
<?php
echo form_open(base_url('addsong/submit') , 'onsubmit="return addsong.submitForm();" accept-charset="UTF-8"');
?>
<input type="text" name="inpt">
<textarea name="txt"></textarea>
<?php
echo form_close();
?>
<?php
//Model
function insert()
{
$data = array(
'input' => $this->input->post('inpt'),
'parag' => $this->input->post('txt')
);
$this->db->insert('sampletbl', $data);
}
?>
Upvotes: 2
Views: 440
Reputation: 2329
Try this:
function insert()
{
$data = array(
'input' => htmlspecialchars($this->input->post('inpt')),
'parag' => htmlspecialchars($this->input->post('txt'))
);
$this->db->insert('sampletbl', $data);
}
This will escape those chars before inserting it in the database
Upvotes: 1