首页 > 解决方案 > 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

标签: php

解决方案


你的表格

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

应该是以下代码:

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

推荐阅读