File "confirm-delete-menu.php"
Full Path: /home/refref/public_html/wp-admin/public/confirm-delete-menu.php
File size: 1.72 KB
MIME-type: text/x-php
Charset: utf-8
<?php
include_once('includes/connect_database.php');
?>
<div id="content" class="container col-md-12">
<?php
if(isset($_POST['btnDelete'])){
if(isset($_GET['id'])){
$ID = $_GET['id'];
}else{
$ID = "";
}
// get image file from menu table
$sql_query = "SELECT news_image
FROM tbl_news
WHERE nid = ?";
$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Bind your variables to replace the ?s
$stmt->bind_param('s', $ID);
// Execute query
$stmt->execute();
// store result
$stmt->store_result();
$stmt->bind_result($news_image);
$stmt->fetch();
$stmt->close();
}
// delete image file from directory
$delete = unlink('upload/'."$news_image");
$delete = unlink('upload/thumbs/'."$news_image");
// delete data from menu table
$sql_query = "DELETE FROM tbl_news
WHERE nid = ?";
$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Bind your variables to replace the ?s
$stmt->bind_param('s', $ID);
// Execute query
$stmt->execute();
// store result
$delete_result = $stmt->store_result();
$stmt->close();
}
// if delete data success back to reservation page
if($delete_result){
header("location: news.php");
}
}
if(isset($_POST['btnNo'])){
header("location: news.php");
}
?>
<h1>Confirm Action</h1>
<hr />
<form method="post">
<p>Are you sure want to delete this news?</p>
<input type="submit" class="btn btn-primary" value="Delete" name="btnDelete"/>
<input type="submit" class="btn btn-danger" value="Cancel" name="btnNo"/>
</form>
<div class="separator"> </div>
</div>
<?php include_once('includes/close_database.php'); ?>