<!-- Step-1 : as we delete the post , category must also decremented --> <!-- approch -1 : fetch the post id and run the query --> <!-- approch -2 : use unlink function for delete the file form a folder ,must provide the whole path --> <?php include "config.php"; $post_id = $_GET['id']; $cat_id = $_GET['catid']; /*-- approch -1 : fetch the post id and run the query --> */ $sql1 = "SELECT * FROM post WHERE post_id = {$post_id}"; $result = mysqli_query($conn, $sql1) or die("Query Failed: Select"); $row = mysqli_fetch_assoc($result); /*-- approch -2 : use unlink function for delete the file form a folder ,must provide the whole path --> */ unlink("upload/".$row['post_img']); /* echo "<pre>"; print_r($row); echo "</pre>"; die(); */ /*-- Step-1 : as we delete the post , category must also decremented */ $sql = "DELETE FROM post WHERE post_id = {$post_id};"; $sql .= "UPDATE category SET post= post-1 WHERE category_id = {$cat_id}"; if(mysqli_multi_query($conn, $sql)){ header("location: {$hostname}/admin/post.php"); }else{ echo "Query Failed"; } ?>