I'm currently working on a CMS-system for school where all of the information comes out of a form, and I ran into a problem. All of the sudden, my 'insert posts' function doesn't work anymore and I have no idea why. I will provide all the necessary code below this text. Thanks in advance for helping! :)
conn.php (for connecting to the database)
<?php
session_start();
if(!isset($_SESSION["loggedin"]))
{
$_SESSION["loggedin"] = "false";
}
$servername = "localhost";
$username = "root";
$password = "";
$database = "cms";
define('BASE_URL', 'http://localhost/cms');
$conn = new mysqli($servername, $username, $password, $database);
if($conn->connect_error)
{
die("Error: " . $conn->connect_error);
}
newpost.php (for inserting posts into the database)
<?php
require 'conn.php';
if($_SESSION["loggedin"] == "true"){}
else
{
header('Location: ' . BASE_URL . '/login.php');
}
if(isset($_POST['save'])){
$title = $_POST['title'];
$description = $_POST['description'];
$text = $_POST['text'];
$course = $_POST['course'];
$insert = $conn->prepare("
INSERT INTO posts (title, description, text, course)
VALUES (:title, :description, :text, :course)
");
$insert->execute([
'title' => $title, 'description' => $description, 'text' => $text, 'course' => $course
]);
header('Location: ' . BASE_URL . '/list.php');
}
?>
<div class="page">
<h1>Add project</h1>
<form method="POST" action="list.php">
<label id="first">Title:</label><br/>
<input type="text" name="title"><br/>
<label id="first">Description:</label><br/>
<textarea rows="5" cols="75" type="text" name="description"></textarea><br/>
<label id="first">Body:</label><br/>
<textarea rows="10" cols="75" type="text" name="text"></textarea><br/>
<label id="first">Vak (DED/SCO/UXU/PTM):</label><br/>
<select name="course">
<option value="DED">DED</option>
<option value="SCO">SCO</option>
<option value="UXU">UXU</option>
<option value="PTM">PTM</option>
</select><br/>
<button type="submit" name="save">Opslaan</button>
</form>