CodeIgniter Forums
Error writing to database with % char from a post variable. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Error writing to database with % char from a post variable. (/showthread.php?tid=46306)



Error writing to database with % char from a post variable. - El Forum - 10-26-2011

[eluser]Unknown[/eluser]
Hello,

I'm working ona project that creates CMS like pages.

But when the data includes a % char codeigniter writes it to database buggy.

for example.

HTML Part
Code:
<form name="myform" action="cms/save" method="post">
<textarea name="mytext">here is some discount % 50 off</textarea>
<input type="submit" value="Send">
</form>

(Here I can't write the orginal text because forum can't save as required too. Orginal text must be without space between % and 50 )

cms.php :
Code:
<?

....

function save(){

$this->db->query("update mycms set mytext=?",$this->input->post('mytext'));

}

......
?>

Query works great but it saves the text to database like this : "here is some discount P off"
% char and the numbers are changing. I don't know why this occurs.

The same error on the forum too, I have noticed that while I was previewing my post. You can check it too. Try to reply by writing "% 50" without space between % and 50.

Do you have an idea about this?