title: Insert data into mysql database using ajax in php
body: <p>I am trying to insert value using ajax in php, but data is not inserted in database. I have taken this code from the questions answered in other question from this site. Can anyone suggest where am I making mistake..?</p>
  
  <pre><code>&lt;script&gt;
    $("#submit").click(function() {
                  var name= $("#name").val();
                  var password= $("#password").val();
  
                  $.ajax({
                      type: "POST",
                      url: "insert.php",
                      data: "name=" + name+ "&amp;password=" + password,
                      success: function(data) {
                         alert("sucess");
                      }
                  });
  
  
              });
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;?php
      //------insert.php------
       $servername = "localhost";
      $username = "username";
      $password = "password";
      $dbname = "dbname";
  
      // Create connection
      $conn = new mysqli($servername, $username, $password,$dbname);
  
      // Check connection
      if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
      } 
  
  
            $name=$_POST['name'];
              $pass=$_POST['password'];
               $sql= mysqli_query($conn,"INSERT INTO insert_tbl(name,pass) VALUES('".$name."','".$pass."')");
  
   ?&gt;
  </code></pre>