This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1个答案)
3年前关闭。
我正在尝试从MySQL表中删除数据。数据将插入到表单中,并且当用户按下Submit时,应从表中删除数据。这是我的代码,但是不起作用。它总是显示错误消息,但是,如果我使用id而不是key,它就可以正常工作。有人可以帮忙吗?
(1个答案)
3年前关闭。
我正在尝试从MySQL表中删除数据。数据将插入到表单中,并且当用户按下Submit时,应从表中删除数据。这是我的代码,但是不起作用。它总是显示错误消息,但是,如果我使用id而不是key,它就可以正常工作。有人可以帮忙吗?
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$mykey = $_POST['proxyKey'];
$sql = "DELETE FROM privateKeys WHERE key = '$mykey'";
if(mysqli_query($db,$sql))
{
header("location: PrivateList.php");
}
else
{
$error = "Your Key is not valid";
}
}
?>
<html>
<head>
<title>Private Proxies</title>
<style type = "text/css">
body
{
font-family:"Lucida Console";
font-size:25px;
color:#f9fbff;
}
.box
{
border:#666666 solid 1px;
width:240px;
height:30px;
}
</style>
</head>
<body bgcolor=#1b1b1c>
<div align = "center">
<div style = "width:300px; border: solid 1px #333333; " align = "left">
<div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Insert private Key</b></div>
<div style = "margin:30px">
<form action = "" method = "post">
<label>Key :</label><input type = "text" name = "proxyKey" class = "box"/><br /><br />
<input type = "submit" value = " Submit "/><br />
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
</div>
</div>
</div>
</body>
</html>
最佳答案
key
是reserved keyword in MySQL,需要通过反引号进行转义。
DELETE FROM privateKeys WHERE `key` = '$mykey'
here----------------^---^
关于php - PHP无法从表中删除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41530437/
10-11 20:03