<?php    
    // 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(); // if it doesnt connect error page
    }
 
    // checking for an id if not then redirects back to customers
    $memberid = 0;
    if (isset($_GET['memberid']))
        $memberid = $_GET['memberid'];
    
    if ($memberid == 0)
    {
        $redirect = "location: http://localhost/gamerental/customers";
        header($redirect);
    }

    // get the details of the members 
    $sql = $dbconn->prepare("SELECT MemberID as memberid,
									Title as title,
                                    Forename as forename, 
									Surname as surname,
                                    Address1 as address1, 
                                    Address2 as address2, 
									Postcode as postcode,
									Telephone as telephone,
									Email as email,
									DataOfBirth as dateofbirth,
									Gender as gender
								    from customers					
                                    where MemberID = ?");
    $sql->bind_param('i', $memberid);	
    // execute the query 
    $sql->execute(); 
    
    // binding the fields
    $sql->bind_result( $memberid, $title,$forename, $surname, $address1, $address2, $postcode, $telephone, $email, $dateofbirth, $gender);
    $sql->store_result();
    $sql->fetch();

  
    //close connection
    mysqli_close($dbconn);
?>
<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>View Customer Details</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">
                    <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">Customer Details</h1> 
                    </div>
					 <div class="row">
                        <div class="col-md-1">
                            <label for="title">Title</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="title" name="title" 
                                   value="<?php echo $title?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="forename">Forename</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="forename" name="forename" 
                                   value="<?php echo $forename?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="surname">Surname</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="surname" name="surname" 
                                   value="<?php echo $surname?>" 
                                   readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-1">
                            <label for="address1">Address1</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="address1" name="address1" 
                                   value="<?php echo $address1?>" 
                                   readonly>
                        </div>
                    </div>                    
                     <div class="row">
                        <div class="col-md-1">
                            <label for="address2">Address2</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="address2" name="address2" 
                                   value="<?php echo $address2?>" 
                                   readonly>
                        </div>
                    </div>                    
                    <div class="row">
                        <div class="col-md-1">
                            <label for="postcode">Postcode</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="postcode" name="postcode" 
                                   value="<?php echo $postcode?>" 
                                   readonly>
                        </div>
                    </div>
                   <div class="row">
                        <div class="col-md-1">
                            <label for="telephone">Telephone</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="telephone" name="telephone" 
                                   value="<?php echo $telephone?>" 
                                   readonly>
                        </div>
                    </div>     
                    <div class="row">
                        <div class="col-md-1">
                            <label for="email">Email</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="email" name="email" 
                                   value="<?php echo $email?>" 
                                   readonly>
                        </div>
                    </div> 
					<div class="row">
                        <div class="col-md-1">
                            <label for="dateofbirth">Date of Birth</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="dateofbirth" name="dateofbirth" 
                                   value="<?php echo $dateofbirth?>" 
                                   readonly>
                        </div>
                    </div>
					<div class="row">
                        <div class="col-md-1">
                            <label for="gender">Gender</label>
                        </div>
                        <div class="col-md-3 mb-3">
                            <input type="text" class="form-control" id="gender" name="gender" 
                                   value="<?php echo $gender?>" 
                                   readonly>
                        </div>
                    </div> 
                    <div class="col-md-2 mb-2">
                            <form action="delete.php" method="post">
                                <input type="hidden" id="memberid" name="memberid" value="<?php echo $memberid?>">
                                <input type="Submit" value="Delete Customer" />
								
                            </form>
							<form action="index.php" method="post">
                                <input type="Submit" value="Back to List" />
                            </form>
                        </div>
               
                    
                
                    </div>
                </main>
            </div>
       

        <!-- include any relevant js files -->
        <?php include "../template/pagefooter.php"; ?>

    </body>
</html>