<!doctype html>
<?php
    // this is the update, get the relevant data
    $id = 0;
    if (isset($_GET['playerid']))
        $id = $_GET['playerid'];

    // go back to list if there is no id
    if ($id == 0 || empty($id))
    {
        $redirect = "location: http://localhost/lfc/goalkeepers";
        //header($redirect);
    }
    
    // we have the id now get the data
    // attempt to connect to the DB
    $dbconn = mysqli_connect("localhost", "root", "", "liverpool");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit(); // you should redirect to some form of error page !!!!
    }
    
    // now get the goalkeeper data, there should be only 1 record
    $sql = $dbconn->prepare("select playerid, lastname 
                                    from goalkeepers 
                                    where playerid = ?");
    $sql->bind_param('i', $id);	
    // execute the query 
    $sql->execute(); 
    
    // we have the data, bind the fields
    $sql->bind_result($playerid, $description);
    $sql->store_result();
	
    // check for 0 rows or > 1 rows, if so redirect to list
    if ($sql->num_rows == 0 || $sql->num_rows > 1)
    {
        $redirect = "location: http://localhost/lfc/goalkeepers";
        //header($redirect);
    }
	
    // get the row of data - you will need a loop if there is more than 1 row
    $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="Liverpool FC">
        <meta name="generator" content="Jekyll v3.8.5">
        <title>Liverpool FC</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 player id -->
                    <form id="custform" action="deletegoalkeeper.php" method="post">
                        <input type="hidden" id="playerid" name="playerid" value="<?php echo $playerid?>">

                        <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 Goalkeeper Details</h1> 
                        </div>
                        <div class="col-md-8 order-md-1">
                            <h5>Do you wish to delete the selected goalkeeper ?</h5>
                        </div>
                        <div class="row">
                            <div class="col-md-4">
                                <input class="btn btn-danger" type="submit" value="Delete">
                                <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>
