Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (63 sloc) 2.99 KB
<?php
require("../dbCon.php");
require("../commonFunctions.php");
if (isset($_GET['NewCatName'])){ //Add new category
$query = "INSERT INTO categories (CategoryName, Description) VALUES (?, ?)";
$stmt = $con->prepare($query);
$stmt ->bind_param("ss", $_GET['NewCatName'], $_GET['NewCatDesc']);
$stmt ->execute();
}elseif (isset($_GET['NewName'])){ //Update old category
$query = "UPDATE categories SET CategoryName = ?, Description = ? WHERE CategoryID = ?";
$stmt = $con->prepare($query);
$stmt ->bind_param("ssd", $_GET['NewName'], $_GET['NewDesc'], $_GET['Category']);
$stmt ->execute();
}
?>
<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuEmp(basename($_SERVER['PHP_SELF'])); ?>
</div>
<div id="contentwrapper">
<div id="contentwrapperLeft">
<form action = "EditCategories.php" method = "get">
<h1>Add Category</h1>
<div class="form-group">
<label>Name</label>
<input type="text" name="NewCatName" id="NewCatName" required>
<label>Description</label>
<input type="text" name="NewCatDesc" id="NewCatDesc" required>
<input type="submit" value="Create Category">
</div>
</form>
</div>
<div id="contentwrapperRight">
<form action = "EditCategories.php" method = "get">
<h1>Edit Category</h1>
<div class="form-group">
<label>Category to Edit</label>
<select name="Category" id="Category" onchange="updateCatNameDesc()">
<?php
$query ="SELECT * FROM categories";
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>";
}
?>
</select>
<label>New Name</label>
<input type="text" name="NewName" id="NewName" required>
<label>New Description</label>
<input type="text" name="NewDesc" id="NewDesc" required>
<input type="submit" value="Update Category">
</div>
</form>
</div>
</div>
</body>
</html>
You can’t perform that action at this time.