这是我的"从图书馆页面删除书籍"
<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 (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."\n";
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>
此页面上的代码正在删除作为图书ID提供的图书,即使没有书籍作为输入分配书籍ID,我也不想要。我需要一种机制,我可以检查一个特定的图书ID在删除表格中的项目之前,是否存在于表格中。
答案 0 :(得分:1)
首先纠正语法:
if($k='YES')
应该是
if($k=='YES')
通过以下方式检查$bkid
的值:
print_r($bkid);
或
var_dump($bkid);