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

    // go back to list if there is no id
    if ($id == 0 || empty($id))
    {
        $redirect = "location: http://localhost/gamerental/price";
        
    }
    
    // we have the id now get the data
    // 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
    }
    
    //gets the price data
    $sql = $dbconn->prepare("select PriceID, rentalprice 
                                    from price 
                                    where PriceID = ?");
    $sql->bind_param('i', $id);	
    // execute the query 
    $sql->execute(); 
    
    // got the data, now binds it
    $sql->bind_result($PriceID, $rentalprice);
    $sql->store_result();
   
    if ($sql->num_rows == 0 || $sql->num_rows > 1)
    {
        $redirect = "location: http://localhost/gamerental/price";
        header($redirect);
    }	
    $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>Game Rental</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">
				<form id="custform" action="updateprice.php" method="post">
                  <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">Update Price </h1> 
                  </div>
                    <div class="col-md-8 order-md-1">
					
					
                        <?php include "addedit.php" ?>
                    </div>
					
                </main>
				
				</form>
            </div>
        </div>

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

    </body>
</html>
