<!doctype html>
<?php
    // get rental data
    $id = 0;
    if (isset($_POST['RentalID']))
        $id = $_POST['RentalID'];

    // go back to list if there is no id
    if ($id == 0 || empty($id))
    {
        $redirect = "location: http://localhost/gamerental/rental";
        
    }
    
  
    // 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
    }
    // now get the rental data
    $sql = $dbconn->prepare("select RentalID,
									MemberID ,
                                    GameID ,
									Expected ,
                                    Returned ,
                                    Hired ,
									Overdue 						
								    from rental							
                                    where RentalID = ?");
    $sql->bind_param('i', $id);	
    // execute the query 
    $sql->execute(); 
    
    // once got the data, bind it. 
    $sql->bind_result($RentalID, $memberid,$gameid, $expected, $returned, $hired, $overdue);
    $sql->store_result();
	
 
    if ($sql->num_rows == 0 || $sql->num_rows > 1)
    {
        $redirect = "location: http://localhost/gamerental/customers";
        
    }
	
    
    $sql->fetch();


?>

<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="Assignment">
        <meta name="generator" content="Jekyll v3.8.5">
        <title>Customers</title>  

        <!-- include any relevant css/js files -->
        <?php include "../template/pageheader.php"; ?>

    </head>
    <body>
        <!-- include the top menu -->
        <?php include "../template/topmenu.php"; ?> 
        <!-- end top menu -->

        <div class="container-fluid">
            <div class="row">
                <!-- insert the side menu -->
                <?php include "../template/sidemenu.php"; ?>	
                <!-- end side menu -->

                <!-- webpage content goes here -->
                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
                    <!-- we need the customer id -->
                    <form id="memberform" action="deleterental.php" method="post">
                        <input type="hidden" id="RentalID" name="RentalID" value="<?php echo $RentalID?>">

                        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                              <h1 class="h1">Delete Rental Detail</h1> 
                        </div>
                        <div class="col-md-8 order-md-1">
                            <h5>Do you wish to delete the rental information?</h5>
                        </div>
                        <div class="row">
                            <div class="col-md-4">
							<!-- Delete button -->
                                <input class="btn btn-danger" type="submit" value="Delete">
								<!-- Cancel button -->
                                <input class="btn btn-warning" type="submit" onclick="form.action='index.php'" 
                                       value="Cancel" formnovalidate>
                            </div>					
                        </div>
                    </form>
                </main>
            </div>
        </div>

        <!-- include any relevant js files -->
        <?php include "../template/pagefooter.php"; ?>

    </body>
</html>
