CSY2028-assignment-1/public/admin/editCategory.php

29 lines
992 B
PHP
Raw Permalink Normal View History

2022-11-19 16:03:54 +00:00
<?php
session_start();
$pageTitle = '';
$stylesheet = '../assets/ibuy.css';
require_once '../../functions.php';
2022-11-20 19:58:30 +00:00
$cat = getFirstAllMatches('category', 'category_id', $_GET['category_id']);
2022-11-20 21:33:42 +00:00
adminCheck(); //checks to see if user is logged in as admin
2022-11-19 16:03:54 +00:00
$pageContent = '<h1> Edit Category</h1>
<form action="editCategory.php" method="POST">
2022-11-20 19:58:30 +00:00
<label>Name</label> <input name="name" type="text" placeholder="'.$cat.'"/>
2022-11-19 16:03:54 +00:00
<input name="submit" type="submit" value="Submit" />
</form>';
require '../../layout.php';
if (isset($_GET['category_id'])) {
$_SESSION['cat_id'] = $_GET['category_id'];
}
else if (isset($_POST['submit'])) {
2022-11-20 13:20:58 +00:00
$pdo = startDB();
2022-11-19 16:03:54 +00:00
$stmt = $pdo->prepare('UPDATE category SET name= :cat_name WHERE category_id= :category_id');
$values = [
'cat_name' => $_POST['name'],
'category_id' => $_SESSION['cat_id']
];
$stmt->execute($values);
unset($_SESSION['cat_id']);
2022-11-20 21:33:42 +00:00
echo '<script>window.location.href = "adminCategories.php";</script>'; //redirect
2022-11-19 16:03:54 +00:00
}
?>