I am having a problem inserting text into a mysql database with jquery and php. I have a jquery script that uses .ajax to pass parameters to a php page that does the insert. The result is text in my database that looks like this "Â CC". I want it to be "* CC". I know this probably has to do with UTF-8 encoding but I can't figure it how to fix it. My DB tables are "utf8_unicode_ci". Can someone tell me what I am doing wrong please?
My .ajax code is...
var comment = "* CC";
$.ajax({
url: "php/add_riw_report.php",
type: "post",
dataType: "json",
data: { comment: comment },
});
And in firebug the POST source is...
&grade=*%C2%A0CC
I have this at the top of my php page...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
And the insert php code is...
$sql = "INSERT INTO
riw_events
VALUES(
mysql_real_escape_string($_POST["comment"])."'
)";
$rs=$db->query($sql);
mysql_queryis an obsolete interface and should not be used in new applications as it's being removed in future versions of PHP. A modern replacement like PDO is not hard to learn. If you're new to PHP, a guide like PHP The Right Way can help explain best practices.