54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
|
|
include("$root/vendor/erusev/parsedown/Parsedown.php");
|
|
|
|
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);
|
|
|
|
$Parsedown = new Parsedown();
|
|
?>
|
|
<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><a href="topics/?cat=<?=$row['id']?>"><?=$row['cat_name']?></a></td></p>
|
|
<td><?=$Parsedown->text($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="5" placeholder="Enter a description for the new category (support Markdown).." required></textarea>
|
|
<input type="submit" value="submit" name="submit"><input type="reset" value="reset">
|
|
</form>
|