I have a simple form that send data to a server via POST message. However, i am getting the error of "Unable to execute query" whenever i click the submit button. Here is my implementation:
sample.html
<!DOCTYPE html>
<html>
<head>
<script>
function pullMore(){
var xmlhttp;
if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome,etc.
xmlhttp = new XMLHttpRequest();
}else{ // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("news_mesgs").innerHTML = xmlhttp.responseText;
}
}
var name = document.getElementById("name");
var email = document.getElementById("email");
var comments = document.getElementById("comment");
var parameters="name"+name.value+"&email="+email.value+"&comments="+comments.value;
xmlhttp.open("POST", "reviews.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(parameters);
}
</script>
</head>
<body style="background-color : #e9e9e9;">
<div> Hello there </div>
<form>
Name: <input type="text" id="name" name="name">
Comment: <input type="text" id="comment" name="comment">
Email: <input type="text" id="email" name="email">
<input type="button" value="Submit" onclick="pullMore()">
</form>
<div id="news_mesgs"> come here </div>
</body>
</html>
reviews.php
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = 'INSERT INTO Reviews (Name, Email, Review) VALUES ('.$_POST['name'].','.$_POST['email'].','.$_POST['comments'].');';
$result = mysql_query($query) or die( "Unable to execute query");
Update: For some reason $_POST["name"]
is appearing empty. I tried to print var_dump($_POST);
for some sample data and this is what i got:
array(2) { ["email"]=> string(11) "abc@abc.com" ["comments"]=> string(5) "hello" } Unable to execute query