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. Also I set it as once the input button is clicked, it will send a "delete" call and the if statement is to checked if the button has been clicked and the call has been received. In addition to retrieving the User ID, the User ID that is to be deleted was passed in through the use of the JavaScript function as shown below.
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>
UPDATE
The delete_userID was passed in through a JavaScript function as shown below.
function bindList() {
var $table = $('#eventsTable');
$table.bootstrapTable({
url: 'list-phaUser.php',
search: true,
pagination: true,
columns: [{
field: 'userID',
title: 'User ID',
sortable: true,
},{
field: 'operate',
title: 'Action',
align: 'center',
sortable: true,
events: operateEvents,
formatter: operateFormatter
},],
});
$(".fixed-table-toolbar").append("<div id='table-title' class='columns columns-left btn-group pull-left'>User List</div>");
$("#divFooter").remove();
$("<div class='row' id='divFooter' style='margin-left:-4%;margin-right:-4%;margin-bottom:-2%;'></div>").insertAfter("#divtb1");
$("#divFooter").load('footer.php');
}
window.operateEvents = {
'click .icon_edit': function (e, value, row, index) {
$("#edit_userID").val(row.userID);
$('#edit_model').modal('show');
},
'click .icon_delete': function (e, value, row, index) {
$("#delete_userID").val(row.userID);
$('#delete_model').modal('show');
}
};
<form>element<form>and that was my problem.