以某种方式查询没有通过我的数据库

时间:2018-04-14 19:39:35

标签: php mysql sql forms content-management-system

我目前正在为学校的CMS系统工作,其中所有信息都来自一个表单,我遇到了问题。突然间,我的插入帖子'功能不再起作用,我不知道为什么。我将在本文下面提供所有必要的代码。在此先感谢您的帮助! :)

conn.php(用于连接数据库)

<?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(用于将帖子插入数据库)

<?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>

0 个答案:

没有答案