<!doctype html>
<?php
    // get the relevant data
    $productid = 0;

    // check for product data
    if(isset($_GET['productid']))
        $productid = $_GET['productid'];

    // go back to list if there is no id
    if ($productid == 0 || empty($productid))
    {
        $redirect = "location: index.php";
        header($redirect);
    }
    
    // get the data
    // attempt to connect to the DB
    $dbconn = mysqli_connect("localhost", "root", "", "PannotinaCoDB");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit();
    }
    
    // now get the category data, there should be only 1 record
    $sql = $dbconn->prepare("select productname, description, price, jewelleryid, designid, colourid, crystalid, charmid, productid
                                    from product
                                    where productid = ?");
    $sql->bind_param('i', $productid);	
    // execute the query 
    $sql->execute(); 
    
    // bind the fields
    $sql->bind_result($productname, $description, $price, $jewelleryid, $designid, $colourid, $crystalid, $charmid, $productid);
    $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: index.php";
        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>
	<?php include "../template/pageheader.php"; ?>
  </head>
  <body>
    
	<?php include "../template/topmenu.php"; ?>

	<div class="container-fluid">
	  <div class="row">
		<?php include "../template/sidemenuproduct.php"; ?>

                <!-- 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">Update Product Details</h1> 
                  </div>
                    <div class="col-md-8 order-md-1">
                        <?php include "edit.php" ?>
                    </div>
                </main>
	  </div>
	</div>
	<?php include "../scripts/pagefooter.php"; ?>
  </body>
</html>

