好的,所以创建了一个从数据库中提取用户id的小表单,我还创建了一个函数。我收到以下错误。似乎无法弄清楚我做错了什么。提前致谢。
这是错误:
无法删除您在SQL语法中出错;检查手册 对应于您的MySQL服务器版本,以获得正确的语法 在' * FROM'用户附近使用' WHERE id = 12'在第1行
这是我的功能
function deleteUser(){
global $db;
$id = $_POST['id'];
$query = "DELETE * FROM 'users' ";
$query .="WHERE id = $id ";
$result = mysqli_query($db, $query);
if (!$result) {
die ("could not delete" . mysqli_error($db));
} else {
echo " user has been deleted";
}
}
这是表格
<?php
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
include ("Includes/header.php");
include ("functionsphp.php");
if(isset($_POST['submit'])){
deleteUser();
}
?>
<h1> Delete user details</h1>
<form action="deleteUsers.php" method="post">
<select name="id">
<?php Showid() ?>
</select>
<p>Select the Id of the user to delete.</p>
<br>
<input type="submit" name="submit" value="DELETE">
答案 0 :(得分:1)
从查询中删除*
delete from user where id = $id
足够了,您的查询应该是这样的
$query = "
DELETE
FROM users
WHERE id = $id
";
答案 1 :(得分:1)
SYNTAX是(删除*)
delete from `users` where `id` = '$id';
或
delete from users where id = '$id';
BACKTICKS(`)。
实施例
123123e34是一个有效的标识符名称,但也是指数编号(我们需要在此处进行反引号)。
答案 2 :(得分:0)
无法在评论中显示。
尝试更改:
DELETE * FROM 'users'
-------^------^-----^--- Change these single quotes to backticks
到
DELETE FROM `users`