JQUERY(JAVASCRIPT-AJAX) database connection problem with PHP-MYSQL..?

ApurvA

New member
JAI MATADI ..

hello .. i have made one form as "FORM.HTML" in which i have used JQUERY,AJAX .. below is my code ..

--------------------------------------------------------------------------------------------------------
FORM.HTML
-------------------------
<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

$(document).ready(function()
{
$(".error").hide();

$(".button").click(function()
{
var nam = $("#name").val();
var eml = $("#email").val();
var phn = $("#phone").val();
if(nam=="")
{
$("#nerror").show();
$("#name").focus();
return false;
}
else
{
$("#nerror").hide();
}


if(eml=="")
{
$("#eerror").show();
$("#email").focus();
return false;
}
else
{
$("#eerror").hide();
}

if(phn=="")
{
$("#perror").show();
$("#phone").focus();
return false;
}
else
{
$("#perror").hide();
}

var dataString = 'name='+ nam + '&email=' + eml + '&phone=' + phn;
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
success: function() {
alert("Submitted Successfully");
}
});
return false;



});
});
</script>

<body>
<form action="">
Name : <input type="text" id="name" name="name" class="text-input" />
<label style="color:#FF0000" class="error" id="nerror">Name is required...</label>
<br />
Email Id : <input type="text" name="email" id="email" class="text-input" />
<label style="color:#FF0000" class="error" id="eerror">Email is required...</label>
<br />
Phone Number : <input type="text" name="phone" id="phone" class="text-input" />
<label style="color:#FF0000" class="error" id="perror">Phone is required...</label>
<br />
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />



</form>
</body>

--------------------------------------------------------------------------------------------------------


now this is my process.php file
in which i m gonna insert my value through code at MYSQL .. this is my code ..

--------------------------------------------------------------------------------------------------------
process.php
----------------------------------
<?php
$nam = $_POST["$name"];
$eml = $_POST["$email"];
$phn = $_POST["$phone"];

mysql_connect("localhost","root","");
mysql_select_db("mytable");
$qry = "insert into jquery(pname,pemail,pphone) values('$nam','$eml','$phn')";
mysql_query($qry);


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

everything working perfectly in FORM.HTML ..
as i m getting errors when i m not typing the particular value ..

but one problem m facing .. i have put all the values in FORM.HTML and now i m also getting the ALERT saying "DATA SUBMITTED" ..

but when i go to MYSQL database i cant see any data as the values are inserting but no values in it .. i mean the blank values are inserting .. with nothing in it ..

i also made some changes in PROCESS.PHP file .. as i tried

--------------------------------------------
$nam = $_POST["$nam"];
$eml = $_POST["$eml"];
$phn = $_POST["$phn"];
--------------------------------------------
in place of the current given at that place at PROCEE.PHP..
but still the values are blank although the values are inserting but blank ..

please help me out .. wht wrong i m doin in this ..

thank you ..

JAI MATADI ...

mitt
 
Back
Top