我有这个删除语句,用于删除mysql表中的一行数据,具体取决于用户在文本字段中输入的电子邮件。
查询似乎没有错误,但数据仍然存在。我有一个INSERT查询与相同的表,并且工作正常。
我的代码:
<?php
require ("database.php");
if($_POST['action'])
{
$email =$_GET['Email'];
// sending query
mysql_query("DELETE FROM List WHERE Email = '$email'")
or die(mysql_error());
header("Location: admin.php");
}
?>
<center><form action="" method="post">
<h1> Delete Email </h1>
<br>
Email:<br><input type="text" name="Email" required placeholder="@alpinemotors.co.za"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" title="Must be a valid email address, eg: user@mail.co.za">
<br/>
<br><h2><input type="submit" name="action" value="Delete Email">
<br></h2>
<h3>
<a href="admin.php"> Main Menu </a>
</h3>
</form>
</center>
答案 0 :(得分:2)
<?php
require ("database.php");
if(isset($_POST['action']))
{
$email =$_POST['Email'];
// sending query
mysql_query("DELETE FROM List WHERE Email = '".$email."'")
or die(mysql_error());
header("Location: admin.php");
}
else
{
//form did not submit
}
?>