title: how to insert data to mysql database with Jquery ajax and php?
body: <p>I am trying to learn Ajax. I am inserting some data to mysql database from a Html Form by php. It works nicely. But my ajax part does not work. I get the success message but data dont go to my php file.  My html and js code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Insertion of data with Ajax&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="myForm" method="POST" action="ajax-save.php"&gt;
  
      Title: &lt;input type="text" name="title" id="title"&gt;&lt;br /&gt;&lt;br /&gt;
      Description: &lt;textarea name="description" id="description" rows="20" cols="40"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;
      Url: &lt;input type="text" name="url" id="url"&gt;&lt;br /&gt;&lt;br /&gt;
  
      &lt;input type="submit" id="submit" name="submit" value="submit"&gt;
  
      &lt;/form&gt;
  
      &lt;script&gt;
  
       $(document).ready(function(){
  
         $("#submit").click(function(){
         $.ajax({
              url: 'ajax-save.php',
              async: true,
              cache: false,
              data: $('#myForm').serialize() ,
              type: 'POST',
              success: function(){
              alert("success");
              clearForm();
              }
          }); 
             return false;
         });
  
      });
  
     &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My php codes are working properly. I have tested it without ajax. Here is my php code.</p>
  
  <pre><code>    $conn = mysql_connect('localhost', 'root', '');
      $db = mysql_select_db('hospital');
  
      if (isset($_POST['title'])) { $title = $_POST['title'];}
      if (isset($_POST['description'])) { $description = $_POST['description'];}
      if (isset($_POST['url'])) { $url = $_POST['url'];}
  
      if(isset($_POST['submit'])){
          if(mysql_query("insert into `wp_upload_video` (`id`, `title`, `description`, `url`) values (NULL, '$title', '$description', '$url')"))
              echo "Successfully Inserted";
          else
              echo "Insertion Failed";
      }
  </code></pre>
  
  <p>Please let me know where is my fault.</p>