chiro-canto/public/forum/categories.php

50 lines
1.5 KiB
PHP

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require "$root/database/credentials.php";
// Connect the database
try{
$db = new PDO("mysql:host=$host;dbname=$database;charset=utf8",
$user,
$password,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
}catch (Exception $e){
die("Error : ".$e->getMessage());
}
$req = $db->prepare('SELECT * FROM `categories`');
$req->execute();
$rows = $req->fetchAll(PDO::FETCH_ASSOC);
?>
<h3>Categories</h3>
<table id="categories">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td><?=$row['cat_name']?></td>
<td><?=$row['cat_description']?></td>
</tr>
<?php
}
?> </tbody>
</table>
<h3>Create a category</h3>
<form action="createcategory.php" method="post">
<label for="title">Category title</label>
<input type="text" id="title" name="title" placeholder="Enter a name for the new category.." required>
<label for="description">Category description</label>
<textarea name="description" id="description" cols="30" rows="10" placeholder="Enter a description for the new category.." required></textarea>
<input type="submit" value="submit" name="submit"><input type="reset" value="reset">
</form>