43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
// Process delete operation after confirmation
|
|
if(isset($_POST["id"]) && !empty($_POST["id"])){
|
|
// Include config file
|
|
require_once "config.php";
|
|
|
|
// Prepare a delete statement
|
|
$sql = "DELETE FROM data_invalid WHERE id = ?";
|
|
|
|
if($stmt = mysqli_prepare($link, $sql)){
|
|
// Bind variables to the prepared statement as parameters
|
|
mysqli_stmt_bind_param($stmt, "i", $param_id);
|
|
|
|
// Set parameters
|
|
$param_id = trim($_POST["id"]);
|
|
|
|
// Attempt to execute the prepared statement
|
|
if(mysqli_stmt_execute($stmt)){
|
|
// Records deleted successfully. Redirect to landing page
|
|
echo '<script language="javascript" type="text/javascript">
|
|
alert("Data berhasil dihapus");
|
|
window.location.replace("data_invalid-index.php");
|
|
</script>';
|
|
exit();
|
|
} else{
|
|
echo "Oops! Something went wrong. Please try again later.";
|
|
}
|
|
}
|
|
|
|
// Close statement
|
|
mysqli_stmt_close($stmt);
|
|
|
|
// Close connection
|
|
mysqli_close($link);
|
|
} else{
|
|
// Check existence of id parameter
|
|
if(empty(trim($_GET["id"]))){
|
|
// URL doesn't contain id parameter. Redirect to error page
|
|
header("location: error.php");
|
|
exit();
|
|
}
|
|
}
|
|
?>
|