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