<?php
//Connects to the database
$con = new PDO("mysql:host=localhost;dbname=gamerental",'root','');


if (isset($_POST["submit"])) {
	$str = $_POST["search"];
	//where to get the data
	$sth = $con->prepare("SELECT * FROM `supplier` WHERE Suppliername = '$str'");

//fetch the data
	$sth->setFetchMode(PDO:: FETCH_OBJ);
	$sth -> execute();

	if($row = $sth->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>Suppliers</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="search" action="searchsupplier.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">Search for Supplier</h1> 
                        </div>
				<div class="col-md-8 order-md-1">
					<table id='customertable' class='table table-bordered table-striped' style='width:100%'>
					<thead>
					<tr>
						<!-- Table goes here -->
						<th>Suppliername</th>
						<th>Address1</th>
						<th>Address2</th>
						<th>Postcode</th>
						<th>Telephone</th>
						<th>Email</th>
					</tr>
					<tr>
						<!-- information from the database is here -->
						<td><?php echo $row->Suppliername; ?></td>
						<td><?php echo $row->Address1;?></td>
						<td><?php echo $row->Address2; ?></td>
						<td><?php echo $row->Postcode;?></td>
						<td><?php echo $row->Telephone; ?></td>
						<td><?php echo $row->Email; ?></td>
				
					</tr>
					</thead>
					</table>
					</div>
						<input type="submit" name="submit" value="Back to List" onclick="form.action='index.php'>
                        
                    </form>
                </main>
            </div>
        </div>
					<?php include "../template/pagefooter.php"; ?>

<?php 
	}
		
		
		else{
			header('Location: index.php');
		}


}

?>
