我的 SQL 语法错误,尽管我提供的数据匹配
error in my SQL syntax, although the data I provide matches
我正在尝试根据登录名、用户名和标题从我的数据库中删除特定行。
但是出现以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near (...)
我尝试仅根据登录名、用户名和标题进行删除,查找了多个与该问题相关的不同 post,但其中 none 提供了解决方案我的问题。我还检查了数据库列名是否有误,也没有。我检查了包含文件夹是否有误,或者我是否弄错了数据库 table 单元格名称,这些都是正确的,所以我现在有点迷路,因此我创建了这个 post .
我的 php 脚本如下所示:
$loginName = $_SESSION['loginName'];
$userName = $_SESSION['userName'];
$id = $_POST['id']; //this is for the hiddenTitle
include_once 'dbConn.php';
$sqli = "DELETE * FROM posts WHERE loginName = ? AND name = ? AND hiddenTitle = ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sqli)) {
var_dump($stmt);
} else {
mysqli_stmt_bind_param($stmt, 'sss', $loginName, $userName, $id);
mysqli_stmt_execute($stmt);
}
这是我提交数据的方式:
function deletePostBtn(del) {
console.log(del.id); //this works
let id = del.id;
let data = {id: id};
$.ajax({
url: 'deletePost.php',
type: 'POST',
data: data,
success: function(response) {
console.log(response); //sends back the error
}
});
}
所以我要实现的目标是: 删除 loginName = $_POST['loginName'], name = $_POST['userName'] 的行和 hiddenTitle = $_POST['id']
你有 DELETE * FROM ...
。你应该 DELETE FROM ...
尝试从您的脚本中删除 *
。它应该只是:
DELETE FROM posts ...
我正在尝试根据登录名、用户名和标题从我的数据库中删除特定行。
但是出现以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near (...)
我尝试仅根据登录名、用户名和标题进行删除,查找了多个与该问题相关的不同 post,但其中 none 提供了解决方案我的问题。我还检查了数据库列名是否有误,也没有。我检查了包含文件夹是否有误,或者我是否弄错了数据库 table 单元格名称,这些都是正确的,所以我现在有点迷路,因此我创建了这个 post .
我的 php 脚本如下所示:
$loginName = $_SESSION['loginName'];
$userName = $_SESSION['userName'];
$id = $_POST['id']; //this is for the hiddenTitle
include_once 'dbConn.php';
$sqli = "DELETE * FROM posts WHERE loginName = ? AND name = ? AND hiddenTitle = ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sqli)) {
var_dump($stmt);
} else {
mysqli_stmt_bind_param($stmt, 'sss', $loginName, $userName, $id);
mysqli_stmt_execute($stmt);
}
这是我提交数据的方式:
function deletePostBtn(del) {
console.log(del.id); //this works
let id = del.id;
let data = {id: id};
$.ajax({
url: 'deletePost.php',
type: 'POST',
data: data,
success: function(response) {
console.log(response); //sends back the error
}
});
}
所以我要实现的目标是: 删除 loginName = $_POST['loginName'], name = $_POST['userName'] 的行和 hiddenTitle = $_POST['id']
你有 DELETE * FROM ...
。你应该 DELETE FROM ...
尝试从您的脚本中删除 *
。它应该只是:
DELETE FROM posts ...