AJAX with PHP and MYSQL database connection ..?

ApurvA

New member
JAI MATADI ..

hello .. i m making database connection using MYSQL and AJAX ..
but m getting a little problem ..
while m tryin to send the data through POST .. its not sending ..
if m writing like this <form name=f1 method="post"> in database m getting the blank values...
and if m writing like this in AJAX CODE -------- a.open("POST","database..etc etc",true);
i m not able to get anything in my database ..

in short when i m using POST method i m not able to send the data in my database .. .. how can i do that ..

everythin workin fine when i m using GET ..



here is my code . .

--------------------------------------------------------------------------------------------------------------
form.html
---------------------
<script type="text/javascript">
function ab()
{
var a1 = document.f1.t1.value;
var a2 = document.f1.t2.value;
if(a1=="")
{
alert("Enter the Name ...!");

document.f1.t1.focus();
return false;

}
else if(a2=="")
{
alert("Enter Email ...!");
document.f1.t2.focus();
return false;
}

if(window.XMLHttpRequest)
{
a = new XMLHttpRequest();
}
else
{
a = new ActiveXObject("Microsoft.XMLHTTP");
}
a.onreadystatechange = function()
{
if(a.readyState== 4 && a.status==200)
{
document.getElementbyId("s1").innerHTML = a.responseText;
}

}

a.open("GET","database.php?q1=" + a1 + "&q2=" + a2,true);
a.send();



}
</script>
</head>

<body>
<form name="f1" >

Enter Name : <input type="text" name="t1" />
<br />
Enter Email : <input type="text" name="t2" />
<br />
<input type="submit" onclick="return ab()" />
<br />
</form>

<span id="s1" style="color:#FF0000"></span>
--------------------------------------------------------------------------------------------------------------





--------------------------------------------------------------------------------------------------------------
database.php
---------------------
<?php

$q1 = $_GET["q1"];
$q2 = $_GET["q2"];

mysql_connect("localhost","root","");
mysql_select_db("mytable");
$qry = "insert into Table2 (uname,email) values('$q1','$q2')";
if(!mysql_query($qry))
{
echo "Error .." . mysql_error();
}
else
{

}



?>
--------------------------------------------------------------------------------------------------------------


i changed from GET to POST .. in my <FORM METHOD=""> and in my AJAX code a.open("POST" , etc ..

but still not working . .please throw me out of this problem ..
 
Back
Top