Contact Us Form Code in PHP Mysql Ajax with Javascript

<?php
date_default_timezone_set('Asia/Kolkata');
$name       =   $_REQUEST['name'];
$emailid    =     $_REQUEST['email'];
$phoneno    =     $_REQUEST['mobile'];
$comment    =     $_REQUEST['comment'];



$conect = mysql_connect("localhost", "USER", "PASSWORD");
mysql_select_db("DATABASE_NAME", $conect);

$sql = "insert into  TABLE_NAME set name='".$name."', email='".$emailid."', phone='".$phoneno."', message='".$comment."', source='Demo Enquiry Page'";
$sql = @mysql_query($sql);
mysql_close($conect);

echo '<p style="padding:8px; color:red; padding-left:10px; font:normal 12px arial; width:425px; margin: 10px auto 0;">Your enquiry has been submitted successfully. </p>';

?>










*****************************HTML***********************************

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>



<div class="floatL cont_lft_side">


  <p>Please fill in your details below.</p>
  

<div style="width:448px; margin:auto;" id="getFormResponseDiv"></div>
<form id="frmCtnt" name="frmCtnt" onsubmit="getFormReponseSubmit(getFormResponseDiv);return false;">

<div class="txt_stl">
<input type="text" value="Enter Your Full Name" name="name" onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';">
</div>

<div class="txt_stl">
<input type="text" value="Enter Your Email Id" name="email" onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';">
</div>

<div class="txt_stl">
<input type="text" value="Enter Your Contact Number" name="mobile" onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';">
</div>

<div class="txt_stl">
<textarea onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';" rows="" cols="" name="comment">Please Write your Query or Comment here.</textarea>
</div>

<input class="or_btn_icon" type="submit" value="Submit">

</form>
  </div>



</body>
</html>

<style>

.askBdr{border-bottom: 1px solid #ccc; padding:10px 0;}
.cont_lft_side {
    width: 450px;
}
.cont_lft_side h3 { border-bottom: 1px solid #ccc; color: #666;font: 17px arial;padding-bottom: 7px;}
.cont_lft_side p {font-family: arial;font-size: 13px;padding: 8px 0 0;}
.txt_stl {width: 100%;}
.txt_stl input {border: 1px solid #cccccc;box-shadow: 0 1px 1px #c4c4c4 inset;color: #666;font: 13px arial;height: 32px;margin-top: 23px;padding-left: 10px;
    width: 100%;}
.txt_stl textarea {border: 1px solid #cccccc;box-shadow: 0 1px 1px #c4c4c4 inset;color: #666;font: 13px arial;height: 100px;margin-top: 23px;padding: 10px 0 0 10px;
    width: 100%;}
.or_btn_icon {background: linear-gradient(to bottom, #db4a37 0%, #c53827 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);border: 1px solid #b0281a;border-radius: 5px;
    box-shadow: 0 1px 0 #e68072 inset; color: #ffffff; cursor: pointer;font: 400 21px arial;margin: 20px 0 0;padding: 5px 30px;}

</style>

<script>

// JavaScript Document
var setURL;
function echeck(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
var pattern=/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|me|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID");
return false;
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID");
return false;
}
if(!pattern.test(str)){         
alert("Invalid E-mail ID");
return false;   
    }
return true;
}


function frmValidate()
{

if(document.frmCtnt.name.value=="" || document.frmCtnt.name.value==null || document.frmCtnt.name.value=="Enter Your Full Name")
{
alert("Your Name can't be blank");
document.frmCtnt.name.focus();
return false;
}
if(document.frmCtnt.email.value=="" || document.frmCtnt.email.value==null || document.frmCtnt.email.value=="Enter Your Email Id")
{
alert("Your Email can't be blank");
document.frmCtnt.email.focus();
return false;
}
if (echeck(document.frmCtnt.email.value)==false){
document.frmCtnt.email.focus();
return false;
}

if(document.frmCtnt.mobile.value=="" || document.frmCtnt.mobile.value==null || document.frmCtnt.mobile.value=="Enter Your Contact Number")
{
alert("Your Mobile can't be blank");
document.frmCtnt.mobile.focus();
return false;
} else if (isNaN(document.frmCtnt.mobile.value)) {
alert("Mobile number contains illegal character");
document.frmCtnt.mobile.focus();
 return false;
}

if(isNaN(document.frmCtnt.mobile.value))
{
alert("Please enter valid Mobile Number");
document.frmCtnt.mobile.focus();
return false;
}
if(document.frmCtnt.comment.value=="" || document.frmCtnt.comment.value==null)
{
alert("Your Comment can't be blank");
document.frmCtnt.comment.focus();
return false;
}
return true;
}


function getFormReponseSubmit(getFormResponseDiv)
{
if(frmValidate()==true)
{
URL="?name="+document.frmCtnt.name.value+"&email="+document.frmCtnt.email.value+"&mobile="+document.frmCtnt.mobile.value+"&comment="+document.frmCtnt.comment.value;

if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("getFormResponseDiv").innerHTML=xmlhttp.responseText;
}else{
document.frmCtnt.name.value="";
document.frmCtnt.email.value="";
document.frmCtnt.mobile.value="";
document.frmCtnt.comment.value="";
document.getElementById("getFormResponseDiv").innerHTML="<br/>&nbsp;Waiting.........<br/>";

}}
xmlhttp.open("POST","http://www.discussdesk.com/online_demo/contact_form/send_contact.php"+URL,true);
xmlhttp.send();
}}
</script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-38304687-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


Source:http://www.discussdesk.com/demo/contact_us_form/index.php