Skip to content
Permalink
bc56221b97
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
62 lines (51 sloc) 2.78 KB
<?php
require("../dbCon.php");
require("../commonFunctions.php");
?>
<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuAdm("Reports.php"); ?>
</div>
<div id='contentwrapper'>
<?php
if (isset($_GET['Category'])){ //Check if category has already been set
$query = "SELECT * FROM `sales by category` WHERE CategoryID = ?
AND ProductName = ? "; //'?' in place of variable
$ProductName = % . $_GET['ProductName'] . %;
$stmt = $con->prepare($query);
$stmt ->bind_param("ds", $_GET['Category'], $ProductName); //Bind category to query, category is taken in as CategoryID, so it's a digit
$stmt ->execute();
$searchResult = $stmt->get_result(); //Get results
makeTable($searchResult); //Make table from results, makeTable code is in commonFunctions.php
}else{ //If category has not been set, show HTML form to pick category
?>
<form action = "Report_Sales.php" method = "get">
<h1>Sales Report</h1>
<div class="form-group">
<label>Select Product Category</label>
<select name="Category" id="Category">
<?php //Populate category drop down by getting categories from DB
$query ="SELECT * FROM categories"; //Query
$stmt = $con->prepare($query); //'con' is name of DB connection, defined in dbCon.php (which is loaded at the top of this file)
$stmt ->execute(); //Run query
$result = $stmt->get_result(); //Put query results into $results array
while($row = mysqli_fetch_array($result)) { //Iterate through each row of results
echo "<option value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>"; //'echo' outputs the given line to the HTML, so this creates a new row in the drop-down for each category
}
?>
</select>
<label>Product Name</label>
<input type="text" name="ProductName" id="ProductName">
<input type="submit" value="View Report">
</div>
</form>
<?php
} //Close bracket from 'else' above
?>
</div>
</body>
</html>