Insert Form Data With Ajax
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title><style>*{margin:0;padding:0;box-sizing:border-box;}body{width:100%;height:100vh;align-items:center;justify-content:center; display:flex;background: #7756;}.form-body{width:600px;height:400px;align-items:center;justify-content:center; display:flex;}#btn_submit{padding:8px 16px;}
.navigation{padding:0;margin:0;}.navigation ul a{text-decoration:none;}.navigation ul a li{text:inline;}</style></head><body><div class="header"></div><div class="navigation"><ul><a href="#"><li>Home</li></a> <a href="#"><li>Sign_Up</li></a> <a href="show.php"><li>Show_Information</li></a> <a href="#"><li>Login</li></a> </ul></div><div class="form-body"><div><form action="" id="regform"method="post">
<p> <span id="result"></span></p> <p><label for="name">Name :</label><br> <input type="text"name="name" id="name"/><br></ p> <p> <label for="father_name">Father Name :</la bel><br> <input type="text"name="fname" id="father_name" /><br></p> <p><label for="mobile">Mobile :</label><br> <input type="text"name="mobile" id="mobile"/><b r> </p><p><label for="dob">DOB :</label><br> <input type="date"name="dob" id="dob"/><br> </p><br><p><input type="submit" name="btn_submit" valu e="submit" id="btn_submit"> </p></form></div></div>
<script src="jquery.min.js"></script> <script>$('#regform').on('submit',function(e){
$('#btn_submit').val("Please Wait"); $('#btn_submit').attr("disabled",true);
$.ajax({url:'regsubmit.php',type:'POST',data:$('#regform').serialize(), success:function(result){$('#regform')[0].reset(); $('#result').html(result); $('#btn_submit').val("Submit"); $('#btn_submit').attr("disabled",false); }});e.preventDefault();});</script>
</body></html>
<?phpsleep(3);$name= $_POST['name'];$fname= $_POST['fname'];$mobile= $_POST['mobile'];$dob= $_POST['dob'];
$con= mysqli_connect('localhost','root','','test'); // print_r($con);$sql = "insert into student(name,fname,mobile,dob) values( '{$name}','{$fname}','{$mobile }','{$dob}')";
$result = mysqli_query($con,$sql); if($result){echo "RegistrationSuccessfully"; }else{echo "Registration NotSuccess";
}
0 Comments