Forum Sign UP Login Contact Us
HOME : Forum : PHP programming : Post New Topic
updating mysqldatabase using ajax and php
jsrain
04:28:12 19:53

Cant get this to work, trying to insert into database, any help would be appreciated


////javascript file
var xmlHttp;
function showUser(str,str1)
{
xmlHttp=GetXmlHttpObject();
if(xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="insert.php";
url=url+"?sid="+Math.random();
url=url+"&u="+str;
url=url+"&p="+str1;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if(xmlHttp.readyState==4||xmlHttp.readyState=="complete")
{
if(xmlHttp.responseText=="Correct")
{
document.location="http://www.jean.yourwebsolution.net/index.html";
}
else
{
alert("Incorrect Username or Password");
}
}
}

function GetXmlHttpObject())
{
var xmlHttp=null;
try
{
//Firefox, Opera 8.0+, Safari, Netscape, Chrome
xmlHttp=new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
/////php file
<?php
$u=$_GET["u"];
$p=$_GET["p"];
$con = mysql_connect("localhost","jeanyour_admin","mYSIT31");
if (!$con)
{
die('Could not connect:'. mysql_error());
}
//create table in login database

mysql_select_db("jeanyour_login",$con);

$sql=("INSERT INTO staff (Naming, Passwording) VALUES ('$u', '$p')");


if (!mysql_query($sql,$con))

echo "Wrong";

else
echo "1 record added";

mysql_close($con)
?>
///htmlfile
<!DOCTYPE HTML>
<html>
<head>
<script src="insertuser.js"></script>
</head>
<body>
<form>

Name:<input type="text" name="naming" />
Password:<input type="password" name="passwording" />


<input type= "button" onClick="showUser('document.all.naming.value, document.all.passwording.value')"; value="Login"/>
</form>
</body>
</html>


subhendu
09:11:12 12:05
Check the if syntax at
if (!mysql_query($sql,$con))
Please Login to post your reply or start a new topic
Privacy Policy | Disclaimer
©2000 - 2014 plus2net.com All rights reserved worldwide