我试图从MySQL表中删除数据。数据以表格形式插入,当用户按下提交时,它应该从表中删除数据。这是我的代码,但它不起作用。它始终显示错误消息,但是,如果我使用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>
答案 0 :(得分:3)
key
是reserved keyword in MySQL,需要通过反引号进行转义。
DELETE FROM privateKeys WHERE `key` = '$mykey'
here----------------^---^