<?php

//Gets the data on the table
$RentalID = 0;
if(isset($_POST['RentalID']))
    $RentalID = $_POST['RentalID'];

// check any rental with no description if not redirects to index page
if ($RentalID == 0)
{
    $redirect = "location: index.php";
    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 rental
$sql = $dbconn->prepare("delete from rental where RentalID = ? ");
$sql->bind_param('i', $RentalID);	

$sql->execute(); 
// close the DB and connection
$sql->close();
$dbconn->close(); 

// redirect back to the list
header('Location: index.php');
 ?>


