Aim
Delete all data where the ID is selected
Problem
The data is not deleted
Error
No Errors was prompted within the developer console
Work Description
Based on what I understand the codes function by retrieving the User ID (delete_userID
) and then passing it into $delete_userID
by using this line mysqli_real_escape_string($conn,$_POST['delete_userID']);
. But I can’t understand why doesn’t the delete query work. I have viewed several online question regarding this and some of it was because of the missing database code which is mysql_select_db("data2017", $conn);
but that does not seem to be the problem for me
Delete Codes
<div class="modal-body">
<p>Do you want to delete?</p>
</div>
<div class="form-group">
<label for="delete_userID" class="control-label">User ID:</label>
<input type="text" class="form-control" id="delete_userID" name="delete_userID" readonly/>
</div>
<div class="modal-footer">
<input type="submit" id="delete" name="delete" class="btn btn-block bt-login" value="Delete" />
<?php
if(isset($_POST['delete'])){
$delete_userID=mysqli_real_escape_string($conn,$_POST['delete_userID']);
mysql_select_db("data2017", $conn);
$sql = "DELETE FROM pha_user WHERE id ='".$delete_userID."'";
$Deletequery=mysqli_query($conn,$sql);
if($Deletequery){
echo "<script>alert('Delete Successful.');</script>";
}
else{
echo "<script>alert('Delete Failed.');</script>";
}
}
?>
</div>