由于某种原因,当我调用此deletebook.php时,查询始终为true,但只有在名称中包含一个单词时才会实际删除该书。任何建议我已经相当困难,可以使用一些帮助。
$book = $_GET["book"];
$email = $_SESSION["email"];
$servername = "";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM books WHERE email = '". $email ."' and name = '". $book ."'";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>
这是来自managebooks.php的相关代码
while($row = mysql_fetch_array($result)) {
echo "<div id='book'>
<ol>
<li>";
echo $row['name'];
echo "</li><li>";
echo $row['price'];
echo "</li>
</ol>
<form action='deleteBook.php' method='get'>
<input type='hidden' name='book' value=". $row['name'] ." />
<button type='submit'>Delete</button></form></div>";
}
答案 0 :(得分:0)
尝试将“value”的值放在引号中。另外,在回显多行html时尝试使用heredoc;它使得引用更容易。 (最佳做法是双引所有HTML属性的所有值。)
答案 1 :(得分:-1)
我认为你应该让你的sql字符串更清洁它可能有帮助
$sql="DELETE FROM books WHERE email='$email' AND name='$book'";
您还可以打印出$ name的值,以实际查看发送到$ sql字符串的内容