Mysql
 sql >> डेटाबेस >  >> RDS >> Mysql

अजाक्स का उपयोग करके php के साथ mysql डेटाबेस में रिकॉर्ड डालें

मैंने इसे हल कर लिया है ... Ajax और MYSQL का उपयोग कैसे करें... पीएचपी कोड

<?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` 
         (`NAME`,`EMAIL_ID`,`PASSWORD`,`CREDITS`,`CREATED_ON`,`MODIFIED_ON`)
         VALUES
         ('$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);
?>

एचटीएमएल फ़ाइल....

<html>
 <HEAD>    
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   </HEAD>
<body>
<div id="status_text">
Fill -ID,NAME,EMAIL_ID,PASSWORD,CREDITS,

ID: <input type="text" id="ID" name="ID"><br><br>
NAME: <input type="text" id="NAME" name="NAME"><br><br>
PASSWORD: <input type="text"  id= "PASSWORD"name="PASSWORD"><br><br>
CREDITS: <input type="text" Id= "CREDITS"name="CREDITS"><br><br>
Email_ID: <input type="text" id="EMAIL_ID"name="EMAIL_ID"><br><br>
CREATED_ON:<input type="text" id="CREATED_ON" name="CREATED_ON"><br><br>
MODIFIED_ON:<input type="text" id="MODIFIED_ON" name="MODIFIED_ON"><br><br>
<input type="submit"  id="btn_submit" name="submit" value="Send"/>
</div>

<script>
<!-- 
//Browser Support Code
 function ajaxFunction(){
 var ajaxRequest;  // The variable that makes Ajax possible!

 try{
   // Opera 8.0+, Firefox, Safari
   ajaxRequest = new XMLHttpRequest();
 }catch (e){
   // Internet Explorer Browsers
   try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e) {
      try{
         ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
         // Something went wrong
         alert("Your browser broke!");
         return false;
      }
   }
 } }
//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 = '&ID='+ID+'&NAME='+NAME+'&PASSWORD='+PASSWORD+'&CREDITS'+CREDITS+'&EMAIL_ID'+EMAIL_ID+'&CREATED_ON'+CREATED_ON+'&MODIFIED_ON'+MODIFIED_ON;
 // alert(postData);
 var myData={"ID":ID,"NAME":NAME,"PASSWORD":PASSWORD,"CREDITS":CREDITS,"EMAIL_ID":EMAIL_ID,"CREATED_ON":CREATED_ON,"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 : myData,
    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('');
         }

}); 
}); 
</script>



</body>
</div>
</html>


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. मुझे अपने डीबी को गोडैडी पर पीडीओ के साथ जोड़ने में समस्या है

  2. पैरामीटरयुक्त तालिका का नाम

  3. MySQL में दो टेबल्स को कैसे जॉइन करें?

  4. java.sql.sqlException कॉलम नहीं मिला

  5. Mysql में माइक्रोसेकंड-सटीक डेटाटाइम कैसे डालें?