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

    // go back to list if there is no id
    if ($id == 0 || empty($id))
    {
        $redirect = "location: http://localhost/gamerental/customers";
        //header($redirect);
    }
    
  
    // 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 member data
    $sql = $dbconn->prepare("select MemberID,
									Title ,
                                    Forename,
									Surname,
                                    Address1,
                                    Address2, 
									Postcode,
									Telephone,
									Email,
									DataOfBirth,
									Gender
								    from customers					
                                    where MemberID = ?");
    $sql->bind_param('i', $id);	
    // execute the query 
    $sql->execute(); 
    
    // once got the data, bind it. 
    $sql->bind_result($memberid, $title, $forename, $surname, $address1, $address2, $postcode, $telephone, $email, $dateofbirth, $gender);
    $sql->store_result();
	
    //checking the rows, if there is 0 then redirects to customer page
    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="deletecustomer.php" method="post">
                        <input type="hidden" id="memberid" name="memberid" value="<?php echo $memberid?>">

                        <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 Customer</h1> 
                        </div>
                        <div class="col-md-8 order-md-1">
                            <h5>Do you wish to delete the customer 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>
