title: Check if the input data is already exists in the DB jquery
body: <p>I have a form that adds device name and device id in mysql database. I have written a jquery script that will check whether the device id is already in the db. If exists it will return false. I have the following code- </p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
                                          &lt;script type="text/javascript"&gt;
                                          $(document).ready(function(){ //newly added 
                                          $('#Submit').click(function() {alert('in');
                                              var checkID = $('#device_id').val(); // assuming this is a input text field
                                              $.post('includes/checkid.php', {'device_id' : checkID}, function(data) {
                                                  if(data=='exist') alert("already exists"); return false;
                                                  else $('#add_dev').submit();
                                              });
                                          });});
                                          &lt;/script&gt;
  
  
  &lt;form method="post" action="includes/process_add.php" name = "add_dev" id = "add_dev"&gt;
                      &lt;tr&gt;&lt;td width="150"&gt;Device ID&lt;/td&gt;&lt;td&gt;:&lt;input type="text" name="device_id" id= "device_id"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Device Name&lt;/td&gt;&lt;td&gt;:&lt;input type="text" name="device_name"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;br&gt;&lt;input type="submit" name="submit" id= "submit" value="Add device"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;/form&gt; 
  </code></pre>
  
  <p>and checkid.php is -</p>
  
  <pre><code>&lt;?php
  include("connection.php");
  $id = $_POST['device_id'];
  $sql = mysql_query("SELECT device_id FROM devices WHERE device_id = '$id'");
  
  if (mysql_num_rows($sql) &gt; 0) {
      echo "exist";
  }else echo 'notexist';
  ?&gt;
  </code></pre>
  
  <p>its not working..</p>