php - if(!empty($_POST['delete'])) query issue
问题描述
I have used this html code
<form method="POST">
<input type="button" id="delete" name="delete" value="delete">
</form>
and the following code for deleting the data from table:
$usr = $_SESSION["user"];
if(empty($_POST['delete'])) {
$query="delete from roombook where Email='$usr'";
$res= mysqli_query($con,$query);
if($res->num_rows>0) {
echo"<script>alert('Deleted');</script>";
}
}else {
echo"<script>alert('delete failed');</script>";
}
} else {
echo"<script>alert('not found');</script>";
}
But it always show me the else statement output only that is: delete failed
解决方案
你的表格
<input type="button" id="delete" name="delete" value="delete">
应该是以下代码:
<input type="submit" id="delete" name="delete" value="delete">
推荐阅读
- java - JAXB 编组每次以随机顺序创建名称空间前缀
- javascript - 数数数组中有多少对象不明白
- ascii - 为什么 hexdump 将 0x0A 解析为一个点?
- optimization - Anylogic:优化期间截断类错误
- javascript - 使用 promise 从 fetch API 返回 JSON 对象
- unity3d - 控制 GameObject renderer Order 如果同类型
- javascript - Mac终端打印一个console.log但不打印另一个
- python - 如果语句不适用于 python 小部件
- kubernetes - 拒绝来自特定命名空间的流量的网络策略
- ms-access - Microsoft Access Sum IIf 表达式