I am ajax'ing data to a Wordpress database and on success showing the text that was written to the database in a div so that people can see what was written
my code looks like this:
$.ajax({
type: "POST",
url: "<?php echo get_bloginfo('template_url').'/insert_comment.php';?>",
data: dataString,
cache: false,
success: function(html){
var returnedArray = html.split('|');
var newhtml = $.trim(unescape(returnedArray[0]));
$("#quote").fadeOut(200,function(){
$("#quote_cont").text(newhtml);
$("#quote span").text(returnedArray[1]) });
$("#quote").fadeIn(200);
}
So for example if the user writes the comment "I don't understand!!"
div #quote displays "I don\'t understand!!", yet when i view the database it was written without the "\".. and if i pull the content straight from the database using PHP i dont get the "\"
EDIT:
changed PHP file below is now CORRECT.. many thanks to @deceze for being patient with me, make sure that your mysql_real_escape_string() comes AFTER your database connection
<?php $con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("robomon_wbc", $con);
$order_id = mysql_real_escape_string($_POST['order_id']);
$email = mysql_real_escape_string($_POST['email']);
$name = mysql_real_escape_string($_POST['name']);
$comment = mysql_real_escape_string($_POST['comment']);
$comment = strip_tags($comment);
mysql_query("UPDATE wp_orderdata SET `comment`='".$comment."', `cus_name` = '".$name."' WHERE `order_id`='".$order_id."' AND `order_email`='".$email."';");
mysql_close($con);
echo $_POST['comment'].'|'.$_POST['name']; ?>