我已经在这个项目上工作了几个小时,需要新的眼光,为什么论坛的信息没有提交到数据库中。
我已检查过与数据库的连接是否正常。每当我尝试向数据库提交一个条目时,它都会显示没有任何问题,并按原样转到https://example.com/beta/index.php?post=success但除auto_incremented id number
之外的任何内容都显示在数据库中。
我的表单页面:
if(!session_id()){
session_start();
}
require('loginregister-master/includes/config.php');
if ($_SESSION['username'] !== admin ) {
header("Location: https://www.example.com/beta");
}
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: loginregister-master/login.php'); }
include('sec/HTTPS.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Post Blog</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<script src="vendor/jquery/jquery.min.js"></script>
</head>
<body>
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title' placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content' placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad' placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author' placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL' placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>
</body>
</html>
'应该'处理提交数据库的位:
<?php
include('connect.php');
$title = mysqli_real_escape_string($link, $_POST['title']);
$content = mysqli_real_escape_string($link, $_POST['content']);
$etad = mysqli_real_escape_string($link, $_POST['etad']);
$author = mysqli_real_escape_string($link, $_POST['author']);
$URL = mysqli_real_escape_string($link, $_POST['URL']);
$sql = "INSERT INTO posts (title, content, etad, author, URL) VALUES ('" . $title . "', '" . $content . "', '" . $etad . "', '" . $author . "', '" . $URL . "')";
mysqli_query($link, $sql);
header("Location: https://www.example.com/beta/index.php?post=success");
?>
当然,处理与数据库连接的位:
<?php
$link = mysqli_connect("localhost", "username", "password", "database_name");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
答案 0 :(得分:1)
您在html标记的名称中错放了"
。只需使用""
。
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title" placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content" placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad" placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author" placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL" placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>