即使表中没有项目,php mysql查询也会删除项目

This is my "DELETE BOOKS FROM LIBRARY PAGE"

<HTML>
     <?php
        global $bkiderr;
     ?>
    <link rel="stylesheet" href="btndeletebooks.css">
    <link rel="stylesheet" href="tablealncenter.css">
    <link rel="stylesheet" href="spanerror.css">
    <p><span class="error">* required field.</span></p>

    <HEAD>
        <h1 align="center">THIS PAGE REMOVES BOOKS FROM THE LIBRARY</h1>
    </HEAD>
    TO REMOVE BOOKS FROM THE LIBRARY<BR><BR>
    <FORM action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
    <table>
        <tr>
             <td>ENTER THE BOOK ID &nbsp;(format -> bkyearbkno ) :</td>
             <td><input type=text name="bkid">
             <span class="error">* <?php echo $bkiderr;?></span>    
        </TR>
    </table>
     <BR>
     CLICK HERE TO REMOVE BOOK:
     <table> 
     <tr>
         <td><input id="rndbutton1" type="submit"  value="REMOVE BOOK FROM LIBRARY" name="submit" title="CLICK HERE TO REMOVE A BOOK"></td>
     </tr>
     </table>
     </br></br>   
    </FORM>
    <?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->query($qchkissuestat,MYSQLI_STORE_RESULT);

                while($res=$reschkissuestat->fetch_array(MYSQLI_NUM))
                {    
                    $k=$res{5};
                    echo $res{0}." ".$k."
";
                    break;
                }    
                if($k='YES')
                {
                    $query="delete from books where bkid='$bkid'";
                    $result=$mysqli->query($query,MYSQLI_STORE_RESULT);
                    echo "YOU REMOVED THE BOOK FROM THE LIBRARY";
                    echo "<table border='1'>";
                    echo "<th>BOOK ID";
                    echo "<tr>";
                    echo "<td class='alncenter'>$bkid</td>";
                    echo "</tr>";
                    echo "</table>";
                    exit();
                }    

            }
        }
        $mysqli->close();
    ?>
     <div class="error">
        <?php
            echo "$bkiderr    <BR>";
        ?>
     </div>
</HTML>

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.

First correct the syntax:

if($k='YES') 

it should be

if($k=='YES')

Check for the value of $bkidby:

print_r($bkid); 

or

var_dump($bkid);