title: php mysql query deleting items even when the item is not present in the table
body: <p>This is my "DELETE BOOKS FROM LIBRARY PAGE"</p>
  
  <pre><code>&lt;HTML&gt;
       &lt;?php
          global $bkiderr;
       ?&gt;
      &lt;link rel="stylesheet" href="btndeletebooks.css"&gt;
      &lt;link rel="stylesheet" href="tablealncenter.css"&gt;
      &lt;link rel="stylesheet" href="spanerror.css"&gt;
      &lt;p&gt;&lt;span class="error"&gt;* required field.&lt;/span&gt;&lt;/p&gt;
  
      &lt;HEAD&gt;
          &lt;h1 align="center"&gt;THIS PAGE REMOVES BOOKS FROM THE LIBRARY&lt;/h1&gt;
      &lt;/HEAD&gt;
      TO REMOVE BOOKS FROM THE LIBRARY&lt;BR&gt;&lt;BR&gt;
      &lt;FORM action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" method="POST"&gt;
      &lt;table&gt;
          &lt;tr&gt;
               &lt;td&gt;ENTER THE BOOK ID &amp;nbsp;(format -&gt; bkyearbkno ) :&lt;/td&gt;
               &lt;td&gt;&lt;input type=text name="bkid"&gt;
               &lt;span class="error"&gt;* &lt;?php echo $bkiderr;?&gt;&lt;/span&gt;    
          &lt;/TR&gt;
      &lt;/table&gt;
       &lt;BR&gt;
       CLICK HERE TO REMOVE BOOK:
       &lt;table&gt; 
       &lt;tr&gt;
           &lt;td&gt;&lt;input id="rndbutton1" type="submit"  value="REMOVE BOOK FROM LIBRARY" name="submit" title="CLICK HERE TO REMOVE A BOOK"&gt;&lt;/td&gt;
       &lt;/tr&gt;
       &lt;/table&gt;
       &lt;/br&gt;&lt;/br&gt;   
      &lt;/FORM&gt;
      &lt;?php
          include 'dbcon.php';
          $qbkname="select bkname from books where bkid=";
  
          #-------------------------REMOVE BOOKS FROM LIBRARY-----------------------#
          if( $_SERVER["REQUEST_METHOD"] == "POST")    
          {
              if (empty($_POST["bkid"]))                       
                  $bkiderr="BOOK ID is required";
              else
                  $bkid = $_POST["bkid"];
              if(isset($bkid))
              {
                  $qchkissuestat="select * from books where bkid='$bkid'";
                  $reschkissuestat=$mysqli-&gt;query($qchkissuestat,MYSQLI_STORE_RESULT);
  
                  while($res=$reschkissuestat-&gt;fetch_array(MYSQLI_NUM))
                  {    
                      $k=$res{5};
                      echo $res{0}." ".$k."\n";
                      break;
                  }    
                  if($k='YES')
                  {
                      $query="delete from books where bkid='$bkid'";
                      $result=$mysqli-&gt;query($query,MYSQLI_STORE_RESULT);
                      echo "YOU REMOVED THE BOOK FROM THE LIBRARY";
                      echo "&lt;table border='1'&gt;";
                      echo "&lt;th&gt;BOOK ID";
                      echo "&lt;tr&gt;";
                      echo "&lt;td class='alncenter'&gt;$bkid&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
                      echo "&lt;/table&gt;";
                      exit();
                  }    
  
              }
          }
          $mysqli-&gt;close();
      ?&gt;
       &lt;div class="error"&gt;
          &lt;?php
              echo "$bkiderr    &lt;BR&gt;";
          ?&gt;
       &lt;/div&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>Code on this page is deleting the books supplied as book ids even when there is no books assigned with the book id given as input,which I do not want.I need a mechanism with which I can check whether a particular book id is present in the table or not before deleting the item from the table.</p>