diff --git a/db.php b/functions.php similarity index 57% rename from db.php rename to functions.php index dd46e07..66eb3c7 100644 --- a/db.php +++ b/functions.php @@ -11,4 +11,15 @@ function fetchCats() { return $cats; } + +function adminCheck() { + if(isset($_SESSION['admin'])) { + if($_SESSION['admin'] != 'y') { + echo ''; + } + } + else { + echo''; + } +} ?> \ No newline at end of file diff --git a/layout.php b/layout.php index f93976d..75ee386 100644 --- a/layout.php +++ b/layout.php @@ -6,7 +6,7 @@ else { $logButton = 'href="../account/login.php">Login'; } -require_once 'db.php'; +require_once 'functions.php'; ?> diff --git a/public/account/register.php b/public/account/register.php index b9d8564..64dc1df 100644 --- a/public/account/register.php +++ b/public/account/register.php @@ -28,6 +28,7 @@ $pageContent = '

Already have an account?Click here to L '; + require '../../layout.php'; if (isset($_POST['submit'])) { diff --git a/public/admin/addCategory.php b/public/admin/addCategory.php index e69de29..c0d7093 100644 --- a/public/admin/addCategory.php +++ b/public/admin/addCategory.php @@ -0,0 +1,27 @@ + Add Category +

+ + +'; +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 ''; +} \ No newline at end of file diff --git a/public/admin/adminCategories.php b/public/admin/adminCategories.php index e0098eb..ad7d130 100644 --- a/public/admin/adminCategories.php +++ b/public/admin/adminCategories.php @@ -2,16 +2,8 @@ session_start(); $pageTitle = 'iBuy - Admin'; $stylesheet = '../assets/ibuy.css'; -if(isset($_SESSION['admin'])) { - if($_SESSION['admin'] != 'y') { - //echo''; - } -} -else { - //echo''; -} - -require_once '../../db.php'; +require_once '../../functions.php'; +adminCheck(); $pageContent = '

Categories Add

'; @@ -21,7 +13,7 @@ function populateContent() { $output = ''; $cats = fetchCats(); foreach ($cats as &$cat) { - $output .= '
  • '. $cat['category_name'] . ' edit delete
  • '; + $output .= '
  • '. $cat['name'] . ' edit delete
  • '; } return $output; }