chiro-canto/public/forum/createcategory.php

62 lines
1.7 KiB
PHP
Raw Normal View History

2021-03-30 10:52:22 +02:00
<?php
function create_category($name, $description)
{
$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('INSERT INTO `categories` (cat_name, cat_description) VALUES (:cat_name, :cat_description)');
$req->execute(array(
"cat_name"=>$name,
"cat_description"=>$description
));
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$_SESSION['error_msg'] = "";
if (isset($_POST['submit']))
{
if (isset($_SESSION['username'])) {
if (isset($_POST['title']))
{
$name = $_POST['title'];
} else
{
$_SESSION['error_msg'] .= "You did not enter a proper category title. \n";
}
if (isset($_POST['description']))
{
$description = $_POST['description'];
} else
{
$_SESSION['error_msg'] .= "You did not enter a proper category description. \n";
}
} else {
$_SESSION['error_msg'] .= "You did not log in.\n";
header('Location: '."/auth/login/");
}
} else
{
$_SESSION['error_msg'] .= "You did not sumit the category creation form.\n";
}
if ($_SESSION['error_msg'] == "")
{
create_category($name, $description);
header('Location: '."/forum");
} else {
header('Location: '."/auth/login/");
}
?>