Permalink
Cannot retrieve contributors at this time
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?
DatabasesPhase2_GroupE/adminPages/ViewProduct.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
179 lines (153 sloc)
7.86 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("../dbCon.php"); | |
require("../commonFunctions.php"); | |
if (isset($_GET['ProductName'])){ //If productName is set, then update product in DB | |
$query = "UPDATE products SET | |
ProductName = ?, | |
SupplierID = ?, | |
CategoryID = ?, | |
QuantityPerUnit = ?, | |
UnitPrice = ?, | |
UnitsInStock = ?, | |
ReorderLevel = ?, | |
Discontinued = ? | |
WHERE ProductID = ?"; | |
// echo $query; | |
$stmt = $con->prepare($query); | |
$stmt ->bind_param("sddsddddd", | |
$_GET['ProductName'], | |
$_GET['SupplierID'], | |
$_GET['CategoryID'], | |
$_GET['QuantityPerUnit'], | |
$_GET['UnitPrice'], | |
$_GET['Stock'], | |
$_GET['ReorderLevel'], | |
$_GET['Discontinued'], | |
$_GET['productID'] | |
); | |
$stmt ->execute(); | |
} | |
$productID = $_GET['productID']; | |
//echo "Welcome " . $_SESSION["userName"] . "!"; | |
?> | |
<html> | |
<head> | |
<link rel="stylesheet" href="../style.css"> | |
</head> | |
<body> | |
<div id="header"> | |
<?php writeMenuAdm('EditProducts.php'); ?> | |
</div> | |
<div id='contentwrapper'> | |
<button onclick="goBack()" style="border:none; background: none;"> <img src="http://mixvassallo.com/website/frontend/css/images/back-button.png" width='100' alt='Return' id = "backbutton"></button> | |
<hr> | |
<?php | |
$sql = "SELECT | |
ProductID as _ProductID, | |
p.SupplierID as _SupplierID, | |
p.CategoryID as _CategoryID, | |
ProductName as Product, | |
CategoryName as Category, | |
CompanyName as Company, | |
QuantityPerUnit as Quantity, | |
FORMAT(p.UnitPrice,2) as Price, | |
UnitsInStock as Stock, | |
ReorderLevel as `Reorder Level`, | |
(select case when Discontinued then 'Yes' else 'No' end) as Discontinued | |
FROM | |
((products p | |
LEFT JOIN suppliers as s ON p.SupplierID = s.SupplierID) | |
LEFT JOIN categories c ON p.CategoryID = c.CategoryID) | |
LEFT JOIN company co ON s.CompanyId = co.CompanyID | |
WHERE ProductID = " . $productID . " | |
order by ProductID ASC"; | |
$result = $con->query($sql); | |
makeTable($result); | |
$result = $con->query($sql); | |
$row = $result->fetch_assoc(); | |
$ProductName = $row['Product']; | |
$SupplierID = $row['_SupplierID']; | |
$CategoryID = $row['_CategoryID']; | |
$Quantity = $row['Quantity']; | |
$UnitPrice = $row['Price']; | |
$UnitsInStock = $row['Stock']; | |
$ReorderLevel = $row['Reorder Level']; | |
$Discontinued = $row['Discontinued']; | |
echo "<hr>"; | |
?> | |
<div id="contentwrapper2" style='height: auto'> | |
<form action = "ViewProduct.php" method = "get"> | |
<h1>Edit Product</h1> | |
<div class="form-group"> | |
<input type="text" name="productID" id="productID" value="<?php echo $productID; ?>" style="display: none"> | |
<label>Product Name</label> | |
<input type="text" name="ProductName" id="ProductName" required value="<?php echo $ProductName; ?>"> | |
<label>Supplier</label> | |
<select name="SupplierID" id="SupplierID"> | |
<?php | |
$query ="SELECT * FROM suppliers s LEFT JOIN company c ON s.CompanyID=c.CompanyID"; | |
$stmt = $con->prepare($query); | |
$stmt ->execute(); | |
$result = $stmt->get_result(); | |
while($row = mysqli_fetch_array($result)){ | |
echo "<option "; | |
if($row['SupplierID'] == $SupplierID) { | |
echo "selected='selected' "; | |
} | |
echo "value='" . $row['SupplierID'] . "'>" . $row['CompanyName'] . "</option>"; | |
} | |
?> | |
</select> | |
<label>Category</label> | |
<select name="CategoryID" id="CategoryID"> | |
<?php | |
$query ="SELECT * FROM categories"; | |
$stmt = $con->prepare($query); | |
$stmt ->execute(); | |
$result = $stmt->get_result(); | |
while($row = mysqli_fetch_array($result)){ | |
echo "<option "; | |
if($row['CategoryID'] == $CategoryID) { | |
echo "selected='selected' "; | |
} | |
echo "value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>"; | |
} | |
?> | |
</select> | |
<label>Quantity Per Unit</label> | |
<input type="text" name="QuantityPerUnit" id="QuantityPerUnit" required value="<?php echo $Quantity; ?>"> | |
<label>Unit Price</label> | |
<input type="text" name="UnitPrice" id="UnitPrice" required value="<?php echo $UnitPrice; ?>"> | |
<label>Stock</label> | |
<input type="text" name="Stock" id="Stock" required value="<?php echo $UnitsInStock; ?>"> | |
<label>Reorder Level</label> | |
<input type="text" name="ReorderLevel" id="ReorderLevel" required value="<?php echo $ReorderLevel; ?>"> | |
<label>Discontinued</label> | |
<select name="Discontinued" id="Discontinued"> | |
<?php | |
echo "<option "; | |
if($Discontinued == "No") { | |
echo "selected='selected' "; | |
} | |
echo "value='0'>No</option>"; | |
echo "<option "; | |
if($Discontinued == "Yes") { | |
echo "selected='selected' "; | |
} | |
echo "value='1'>Yes</option>"; | |
?> | |
</select> | |
<input type="submit" value="Save Changes"> | |
</div> | |
</form> | |
</div> | |
<hr> | |
<?php | |
$sql = "SELECT Picture FROM Products LEFT JOIN Categories ON Products.CategoryID = Categories.CategoryID WHERE ProductID=" . $productID; | |
$result = $con->query($sql); | |
$row = $result->fetch_assoc(); | |
loadPicture($row['Picture']); | |
?> | |
</div> | |
</body> | |
</html> |