Hi
i am having an issue inserting data into mysql if the data has special characters. For example, if i try to add “john’s pencil”, it does not add it to my database. Here’s my code:
[CODE]
var text=textbox.value;
var xhr;
if (window.XMLHttpRequest) // Object of the current windows
{
xhr = new XMLHttpRequest(); // Firefox, Safari, …
}
else if (window.ActiveXObject) // ActiveX version
{
xhr = new ActiveXObject(“Microsoft.XMLHTTP”); // Internet Explorer
}
xhr.onreadystatechange = function(){
if(this.readyState == 4){
textbox.value=”Response Added”;
}
}
xhr.open(“GET”, “insert.php?user=”+user+”&text=”+text, true);
xhr.send(null);
textbox and user are set earlier, so they do exist when this is called.
and here is insert.php:
[CODE]<?php
$user=$_GET[‘user’];
$text=$_GET[‘text’];
$con=mysql_connect(“localhost”,$username,$password);
mysql_select_db($database,$con);
$query=”INSERT INTO responses VALUES(NULL,’$user’,’$text’);”;
mysql_query($query);
echo $user;
mysql_close($con);
?>
I tried adding encodeURIComponent on the JS code, but that didn’t work.
The weird thing is that I can see the call made by ajax on firebug is:
[CODE]GET http://localhost/Website/insert.php?user=Guest&text=john%27s%20book
so I can’t figure out why the ‘ breaks it.
Thanks for the help