addCategory page
This commit is contained in:
parent
bacd3f72d3
commit
80f967eb3a
|
|
@ -11,4 +11,15 @@ function fetchCats() {
|
||||||
|
|
||||||
return $cats;
|
return $cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function adminCheck() {
|
||||||
|
if(isset($_SESSION['admin'])) {
|
||||||
|
if($_SESSION['admin'] != 'y') {
|
||||||
|
echo '<script>window.location.href = "../index.php";</script>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo'<script>window.location.href = "../index.php";</script>';
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -6,7 +6,7 @@ else {
|
||||||
$logButton = 'href="../account/login.php">Login';
|
$logButton = 'href="../account/login.php">Login';
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once 'db.php';
|
require_once 'functions.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ $pageContent = '<p>Already have an account?<a href=\'login.php\'>Click here to L
|
||||||
<label>Password</label> <input name="password" type="text" />
|
<label>Password</label> <input name="password" type="text" />
|
||||||
<input name="submit" type="submit" value="Submit" />
|
<input name="submit" type="submit" value="Submit" />
|
||||||
</form>';
|
</form>';
|
||||||
|
|
||||||
require '../../layout.php';
|
require '../../layout.php';
|
||||||
|
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$pageTitle ='iBuy - Add Category';
|
||||||
|
$stylesheet = '../assets/ibuy.css';
|
||||||
|
require_once '../../functions.php';
|
||||||
|
adminCheck();
|
||||||
|
$pageContent = '<h1> Add Category</h1>
|
||||||
|
<form action="addCategory.php" method="POST">
|
||||||
|
<label>Name</label> <input name="name" type="text" />
|
||||||
|
<input name="submit" type="submit" value="Submit" />
|
||||||
|
</form>';
|
||||||
|
require '../../layout.php';
|
||||||
|
|
||||||
|
if (isset($_POST['submit'])) {
|
||||||
|
$server = 'mysql';
|
||||||
|
$username = 'student';
|
||||||
|
$password = 'student';
|
||||||
|
$schema = 'assignment1';
|
||||||
|
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||||
|
$stmt = $pdo->prepare('INSERT INTO category(name)
|
||||||
|
VALUES(:name)');
|
||||||
|
$values = [
|
||||||
|
'name' => $_POST['name']
|
||||||
|
];
|
||||||
|
$stmt->execute($values);
|
||||||
|
echo '<script>window.location.href = "adminCategories.php";</script>';
|
||||||
|
}
|
||||||
|
|
@ -2,16 +2,8 @@
|
||||||
session_start();
|
session_start();
|
||||||
$pageTitle = 'iBuy - Admin';
|
$pageTitle = 'iBuy - Admin';
|
||||||
$stylesheet = '../assets/ibuy.css';
|
$stylesheet = '../assets/ibuy.css';
|
||||||
if(isset($_SESSION['admin'])) {
|
require_once '../../functions.php';
|
||||||
if($_SESSION['admin'] != 'y') {
|
adminCheck();
|
||||||
//echo'<script>window.location.href = "../index.php";</script>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//echo'<script>window.location.href = "../index.php";</script>';
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once '../../db.php';
|
|
||||||
$pageContent = '<h1>Categories <a href="addCategory.php">Add</a></h1>
|
$pageContent = '<h1>Categories <a href="addCategory.php">Add</a></h1>
|
||||||
<ul>'. populateContent() .'</ul>';
|
<ul>'. populateContent() .'</ul>';
|
||||||
|
|
||||||
|
|
@ -21,7 +13,7 @@ function populateContent() {
|
||||||
$output = '';
|
$output = '';
|
||||||
$cats = fetchCats();
|
$cats = fetchCats();
|
||||||
foreach ($cats as &$cat) {
|
foreach ($cats as &$cat) {
|
||||||
$output .= '<li>'. $cat['category_name'] . ' <a href="editCategory.php?category_id='. urlencode($cat['category_id']) .'">edit</a> <a href="deleteCategory.php?category_id='. urlencode($cat['category_id']). '">delete</a></li>';
|
$output .= '<li>'. $cat['name'] . ' <a href="editCategory.php?category_id='. urlencode($cat['category_id']) .'">edit</a> <a href="deleteCategory.php?category_id='. urlencode($cat['category_id']). '">delete</a></li>';
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue