douzhi1972 2018-04-14 19:39
浏览 31

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

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>

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探