<?php

//Gets the data on the category table
$categoryid = 0;
if(isset($_POST['categoryid']))
    $categoryid = $_POST['categoryid'];

// check any category with no description if not redirects to index page
if ($categoryid == 0)
{
    $redirect = "location: index.php";
   // header($redirect);
    exit();
    
}

// attempt to connect to the DB
$dbconn = mysqli_connect("localhost", "root", "", "gamerental");
if ($dbconn->connect_error > 0) {
    die('Could not connect: ' . $dbconn->connect_error);
    exit(); // Error page
}

// delete the category
$sql = $dbconn->prepare("delete from category where CategoryID = ? ");
$sql->bind_param('i', $categoryid);	

$sql->execute(); 
// close the DB and connection
$sql->close();
$dbconn->close(); 

// redirect back to the list
header('Location: index.php');
 ?>


