3 回答
TA贡献1806条经验 获得超8个赞
当您编写时SELECT * FROM...
,*
意味着一切,即所有字段。该行的所有部分。删除时使用相同的语法没有任何意义,因为您只能删除整行。这就是为什么语法是DELETE FROM...
TA贡献1807条经验 获得超9个赞
我现在为此输入信息,因为我遇到了同样的问题。当我去给出答案时,它没有帮助。可能是因为该问题并未给出所有相关脚本的完整描述:HTML,Javascript,php等。以下是我用来从数据库表中删除的正确php脚本的结构
<?php
$servername = "localhost";
$username = "user";
$password = "0007";
$dbname = "CRCSystems";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$tblname = test_input($_POST["tblname"]);
$names = test_input($_POST["names"]);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql = "SELECT * FROM $tblname WHERE Names = '$names'";
if (mysqli_query($conn, $sql)) {
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($result);
if ($row) {
$sql = "DELETE FROM $tblname WHERE Names = '$names'";
$result = mysqli_query($conn, $sql);
echo 1; //record deleted
} else {
echo 0; //record does not exist
}
}
mysqli_close($conn);
?>
添加回答
举报