Friday 10 June 2016

Insert Form data using Jquery Post Method with PHP Mysql

This blog covers how can we insert form data into Mysql table using JQuery post method by using PHP programming language without page refresh. This method will loads a page from the server using a POST HTTP request. We can use JQuery Ajax method or Jquery Post method to communicate form data to php script. But here we have discuss JQuery post method and how can we use jquery post method to insert form data into mysql table by using php script without refreshing event of page. By using this method we can increase the speed of form submission data to server this is because here page is not refresh and data is submitted to server without any page refreshing event. So that speed of out web application will increase by using this JQuery post method of submit form data to server. In Current time most of the website is used this concept for submitting form data. This JQuery Post method call the php script and php script process the data and callback for success inserting of data to JQuery Post method. This way we can insert form data using JQuery post method. If you get more information regarding this, you can also show the video which you can find in this post.

Source Code


 -- Table structure for table `tbl_form`  
  `id` int(11) NOT NULL AUTO_INCREMENT,  
  `name` text NOT NULL,  
  `message` text NOT NULL,  
  PRIMARY KEY (`id`)  
 -- Dumping data for table `tbl_form`  


 <!DOCTYPE html>  
           <title>Webslesson Tutorial | Insert Form data using Jquery Post Method with PHP Mysql</title>  
           <link rel="stylesheet" href="" />  
           <script src=""></script>  
           <script src=""></script>  
           <br /><br />  
           <div class="container" style="width:600px;">  
                <h3>Insert Form data using Jquery Post Method with PHP Mysql</h3><br />  
                <form id="submit_form">  
                     <input type="text" name="name" id="name" class="form-control" />  
                     <br />  
                     <textarea name="message" id="message" class="form-control"></textarea>  
                     <br />  
                     <input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />  
                <div id="response"></div>  
           $('#submit').prop('disabled', true);  
           var name = $('#name').val();  
           var message = $('#message').val();  
           if(name == '' || message == '')  
                $('#response').html('<span class="text-danger">All Fields are required</span>')  
                $('#submit').prop('disabled', false);  
                          $('#submit').prop("disabled", false);  
                          }, 5000);  


 $connect = mysqli_connect("localhost", "root", "", "testing");  
      $name = mysqli_real_escape_string($connect, $_POST["name"]);  
      $message = mysqli_real_escape_string($connect, $_POST["message"]);  
      $query = "INSERT INTO tbl_form(name, message) VALUES('".$name."', '".$message."')";  
      if(mysqli_query($connect, $query))  
           echo '<p>You have entered</p>';  
           echo '<p>Name:'.$name.'</p>';  
           echo '<p>Message : '.$message.'</p>';  

1 comment: