this one is the page where the input is made and I placed the AJAX
<html>
<head>
<script type="text/javascript">
function insertUser()
{
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("POST","insert.php",true);
xmlhttp.send("uname="document.getElementById("uname").value,pass="document.getElementById("pass").value");
}
</script>
</head>
<body>
<form>
Firstname: <input type="text" name="uname" />
Lastname: <input type="text" name="pass" />
<input type="button" value="click me!" onclick="insertUser()"/>
</form>
</body>
</html>
this is the php code
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_forum", $con);
$sql="INSERT INTO user (user_name,user_password)
VALUES
('$_POST[uname]','$_POST[pass]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
the part with xmlhttp.send(); is the one I'm having trouble with, isnt that the part that I should put in the values I will send to the php file? or am I wrong?

New Topic/Question
Reply




MultiQuote





|