PHP 无法从 table 中删除
PHP can't delete from table
我正在尝试从 MySQL table 中删除数据。数据被插入到一个表单中,当用户按下提交时,它应该从 table 中删除数据。这是我的代码,但它不起作用。它总是显示错误消息,但是,如果我使用 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----------------^---^
我正在尝试从 MySQL table 中删除数据。数据被插入到一个表单中,当用户按下提交时,它应该从 table 中删除数据。这是我的代码,但它不起作用。它总是显示错误消息,但是,如果我使用 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----------------^---^