How to delete a record in php mysql using the AJAX.
here's the code:
delete_record.php
<?php
require_once "../include/connection.php";
if ($_REQUEST['rowid']) {
$sql = "DELETE FROM lesson1 WHERE id='".$_REQUEST['rowid']."'";
if (mysqli_query($conn, $sql) {
//echo "Success";
} else {
//echo "Error: $sql";
mysqli_error($conn);
}
}
myqli_close($conn);
?>
index.php
<script type="text/javascript">
var rowId = null;
$(document).ready(function() {
$(document).on('click', '#btnDel', function(e) {
e.preventDefault();
rowId = $(this).attr('data-id');
});
$('#accDelBtn').click(function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: 'delete_record.php',
data: 'rowid=' + rowId,
success: function(data) {
alert('Records were deleted successfully');
$('#modalDelete').modal('hide');
}
});
})
});
</script>
what I'm trying to here is to delete a record. when I'm clicking the delete. message is success but the data is not deleted.
You can try:
if ($_REQUEST['rowid']) {}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.