Guys, I was trying to save a data using ajax but it seems not working. is there something wrong here? Here’s my javascript code:
[CODE]
<script type=”text/javascript”>
function saveitem()
{
name=document.getElementById(“txtname”).value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.open(“GET”,”save.php?q=”+name,true);
xmlhttp.send();
}
</script>
<body>
<form name=”frm1″>
<input type=”text” name=”txtname” id=”txtname”>
<input type=”submit” name=”cmdsave” id=”cmdsave” onClick=”saveitem();”>
</form>
</body>
and here’s my save.php code:
[CODE]
<?php
$name = $_GET[‘q’];
mysql_connect(‘192.168.100.9′,’root’,’1234′) or die(“Unable to connect to MySQL”);
mysql_select_db(sampledb) or die(“Unable to select a database”);
$query = “insert into table1(name,age) values(‘$name’,”)”;
mysql_query($query) or die(“error in query”);
?>
Now, what I’m trying to do is to transfer the inputted item to save.php so that in can be saved to my database. But save.php doesn’t seem to receive the data or maybe my javascript isn’t working. Can someone tell me why?