AJAX HTML PHP question
- by Jordan Pagaduan
This is my scripts.js
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","inputProcess.php?q="+str,true);
xmlhttp.send();
}
This is my HTML
<script type="text/javascript" src="scripts.js"></script>
<form>
Type your name here : <input type="text" onkeypress="showHint(this.value)" name="name" />
</form>
This is my PHP file
<?php
$q = $_GET['q'];
$dbc=mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db('input_oop') or die (mysql_error());
$sql = "INSERT INTO users set name = '".$q."'";
mysql_query($sql) or die (mysql_error());
?>
When the text is save in my database it will save 5 times or up.