你好我有我的代码我只想删除一个特定的行,但是当我运行我的程序时它会删除所有代码..?
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "csedb";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to delete a record
$sql = "DELETE FROM addform WHERE id_stu=$id_stu";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
if($sql)
{
header('location:student.php');
}
mysqli_close($conn);
?>
</body>
</html>
答案 0 :(得分:1)
将值赋予where子句,如
$sql = "DELETE FROM addform WHERE id_stu=<id_or_value>";
希望有所帮助
答案 1 :(得分:0)
您需要为id_stu提供一个值 DELETE FROM addform WHERE id_stu =您的号码
答案 2 :(得分:0)
你必须给出一个值:
$sql = "DELETE FROM addform WHERE id_stu = 1";
答案 3 :(得分:0)
您需要传递要删除的行的特定ID。
$sql = "DELETE FROM addform WHERE id_stu=id_to_delete";
另外,不要忘记了解如何防止sql注入。