title: Insert records to mysql database with php using Ajax
body: <p><strong>How to do coding of this Code With Using Ajax.Please Help.</strong>
  I am Bignner here and i have written this code it's working but i want to use with ajax this because don't want to reload the page...?</p>
  
  <p>PHP File </p>
  
  <pre><code>    //Code For Making Form And getting Data…..
      &lt;html&gt;
      &lt;body&gt;
      Fill -ID,NAME,EMAIL_ID,PASSWORD,CREDITS,
      &lt;form action="Form_Data.php" method="post"&gt; 
  
  ID: &lt;input type="text" name="ID"&gt;&lt;br&gt;&lt;br&gt;
  NAME: &lt;input type="text" name="NAME"&gt;&lt;br&gt;&lt;br&gt;
  PASSWORD: &lt;input type="text" name="PASSWORD"&gt;&lt;br&gt;&lt;br&gt;
  CREDITS: &lt;input type="text" name="CREDITS"&gt;&lt;br&gt;&lt;br&gt;
  E_mail: &lt;input type="text" name="EMAIL_ID"&gt;&lt;br&gt;&lt;br&gt;
  CREATED_ON:&lt;input type="text" name="CREATED_ON"&gt;&lt;br&gt;&lt;br&gt;
  MODIFIED_ON:&lt;input type="text" name="MODIFIED_ON"&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>//code for taking data from form data.</p>
  
  <pre><code>&lt;html&gt;
  &lt;?php
  include 'connnect.php';
     mysql_set_charset('utf8');
     //query for insert data into tables
     $ID = $_POST['ID'];
     $NAME =$_POST['NAME'];
     $EMAIL_ID =$_POST['EMAIL_ID'];
     $PASSWORD =$_POST['PASSWORD'];
     $CREDITS =$_POST['CREDITS'];
     $CREATED_ON=$_POST['CREATED_ON'];
     $MODIFIED_ON=$_POST['MODIFIED_ON'];
  
     $query = "INSERT INTO `user_table` 
           (`ID`,`NAME`,`EMAIL_ID`,`PASSWORD`,`CREDITS`,`CREATED_ON`,`MODIFIED_ON`)
           VALUES
           ('$ID','$NAME','$EMAIL_ID','$PASSWORD','$CREDITS','$CREATED_ON','$MODIFIED_ON')";
           $query_run= mysql_query($query);
           $retval=mysql_query($query,$conn);
             if ($query_run)
     { echo 'It is working';
  }
     mysql_close($conn);
  ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have Tried Yet ... Is Blewo...</p>
  
  <pre><code>file for html and ajax
      &lt;html&gt;
       &lt;HEAD&gt;    
         &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
         &lt;/HEAD&gt;
      &lt;body&gt;
      &lt;div id="status_text"&gt;
      Fill -ID,NAME,EMAIL_ID,PASSWORD,CREDITS,
      &lt;form onsubmit="return false" method="post"&gt;
      ID: &lt;input type="text" id="ID" name="ID"&gt;&lt;br&gt;&lt;br&gt;
      NAME: &lt;input type="text" id="NMAE" name="NAME"&gt;&lt;br&gt;&lt;br&gt;
      PASSWORD: &lt;input type="text"  id= "PASSWORD"name="PASSWORD"&gt;&lt;br&gt;&lt;br&gt;
      CREDITS: &lt;input type="text" Id= "CREDITS"name="CREDITS"&gt;&lt;br&gt;&lt;br&gt;
      Email_ID: &lt;input type="text" id="Email_ID"name="EMAIL_ID"&gt;&lt;br&gt;&lt;br&gt;
      CREATED_ON:&lt;input type="text" id="CREATED_ON" name="CREATED_ON"&gt;&lt;br&gt;&lt;br&gt;
      MODIFIED_ON:&lt;input type="text" id="MODIFIED_ON" name="MODIFIED_ON"&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="submit"  id="btn_submit" name="submit" value="Send"&gt;
      &lt;/div&gt;
  
  &lt;script&gt;
  
  //on the click of the submit button 
  $("#btn_submit").click(function(){
      //get the form values
   var ID = $('#ID').val();     
   var NAME = $('#NAME').val();     
   var PASSWORD = $('#PASSWORD').val();
   var CREDITS = $('#CREDITS').val();
   var EMAIL_ID = $('#EMAIL_ID').val();
   var CREATED_ON = $('#CREATED_ON').val();
   var MODIFIED_ON = $('#MODIFIED_ON').val();
   //make the postdata
   var postData = '&amp;ID='+ID+'&amp;NAME='+NAME+'&amp;PASSWORD='+PASSWORD+'&amp;REDITS'+CREDITS+'&amp;EMAIL_ID'+EMAIL_ID+'&amp;CREATED_ON'+CREATED_ON+'&amp;MODIFIED_ON'+MODIFIED_ON;
   //call your .php script in the background, 
   //when it returns it will call the success function if the request was successful or 
   //the error one if there was an issue (like a 404, 500 or any other error status)
  });
   $.ajax({
      url : "Form_Data.php",
      type: "POST",
      data : postData,
      success: function(data,status,  xhr)
       {
          //if success then just output the text to the status div then clear the form inputs to prepare for new data
          $("#status_text").html(data);
          $('#ID').val();
          $('#NAME').val('');
          $('#PASSWORD').val('');
          $('#EMAIL_ID').val('');
          $('#CREATED_ON').val('');
          $('#MODIFIED_ON').val('');
           }
  
  });  
  &lt;/script&gt;
  
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>code for query...</p>
  
  <pre><code>&lt;html&gt;
  &lt;?php
  include 'connnect.php';
     mysql_set_charset('utf8');
     //query for insert data into tables
     $ID = $_POST['ID'];
     $NAME =$_POST['NAME'];
     $EMAIL_ID =$_POST['EMAIL_ID'];
     $PASSWORD =$_POST['PASSWORD'];
     $CREDITS =$_POST['CREDITS'];
     $CREATED_ON=$_POST['CREATED_ON'];
     $MODIFIED_ON=$_POST['MODIFIED_ON'];
  
  
  $query = "INSERT INTO `user_table` 
           (`ID`,`NAME`,`EMAIL_ID`,`PASSWORD`,`CREDITS`,`CREATED_ON`,`MODIFIED_ON`)
           VALUES
           ('$ID','$NAME','$EMAIL_ID','$PASSWORD','$CREDITS','$CREATED_ON','$MODIFIED_ON')";
           $query_run= mysql_query($query);
           $retval=mysql_query($query,$conn);
             if ($query_run)
     { echo 'It is working';
  }
     mysql_close($conn);
  ?&gt;
  &lt;/html&gt;
  </code></pre>