if(!empty($ _ POST ['delete']))查询问题

时间:2019-03-07 17:19:23

标签: php

我已经使用了此html代码

<form method="POST">
    <input type="button" id="delete" name="delete" value="delete">
</form>

以及以下用于从表中删除数据的代码:

$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>"; 
}

但是它总是向我显示else语句的输出,即:删除失败

1 个答案:

答案 0 :(得分:0)

您的表格

 <input type="button" id="delete" name="delete" value="delete">

应为以下代码:

 <input type="submit" id="delete" name="delete" value="delete">