Nav bar now populates from categories db table

This commit is contained in:
Joshua Perry 2022-11-15 13:59:42 +00:00
parent f8e8bfe054
commit ecd8c35b8a
2 changed files with 17 additions and 11 deletions

View File

@ -32,13 +32,19 @@ else {
<nav> <!--TODO: Populate this list from the categories defined by the admins--> <nav> <!--TODO: Populate this list from the categories defined by the admins-->
<ul> <ul>
<li><a class="categoryLink" href="../index.php?pageHeading=Home+%26+Garden">Home &amp; Garden</a></li> <?php
<li><a class="categoryLink" href="../index.php?pageHeading=Electronics">Electronics</a></li> $server = 'mysql';
<li><a class="categoryLink" href="../index.php?pageHeading=Fashion">Fashion</a></li> $username = 'student';
<li><a class="categoryLink" href="../index.php?pageHeading=Sport">Sport</a></li> $password = 'student';
<li><a class="categoryLink" href="../index.php?pageHeading=Health">Health</a></li> $schema = 'ibuy';
<li><a class="categoryLink" href="../index.php?pageHeading=Toys">Toys</a></li> $pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
<li><a class="categoryLink" href="../index.php?pageHeading=Motors">Motors</a></li> $stmt = $pdo->prepare('SELECT * FROM categories');
$stmt->execute();
$cats = $stmt->fetchAll();
foreach ($cats as &$cat) {
echo '<li><a class="categoryLink" href="../index.php?pageHeading='. urlencode($cat['category_name']) .'">'. $cat['category_name'] .'</a></li>';
}
?>
<li><a class="categoryLink" <?php echo $logButton?></a></li> <li><a class="categoryLink" <?php echo $logButton?></a></li>
</ul> </ul>
</nav> </nav>

View File

@ -10,10 +10,10 @@ $pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to
$stylesheet = '../assets/ibuy.css'; $stylesheet = '../assets/ibuy.css';
require '../../layout.php'; require '../../layout.php';
$server = 'mysql'; $server = 'mysql';
$username = 'student'; $username = 'student';
$password = 'student'; $password = 'student';
$schema = 'ibuy'; $schema = 'ibuy';
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password); $pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email'); $stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
$values = [ $values = [