我正在构建一个简单的博客系统,我可以通过php页面将条目发布到mysql中的数据库。每当我发布一个条目时,它似乎不会出现在数据库中,我无法找到问题。这是我的php:
<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if(isset($_SESSION['username']))
{
$username = ucfirst($_SESSION['username']);
if($_POST['submit']) {
$title = $_POST['title'];
$subtitle = $_POST['subtitle'];
$content = $_POST['content'];
include_once("connection.php");
$sql = "INSERT INTO blog (title, subtitle, content) VALUES ('$title', '$subtitle', '$content')";
mysqli_query($dbCon, $sql);
echo "Blog entry posted";
}
}
else{
header('Location: login.php');
die();
}
?>
标题,副标题和内容标签位于此下方的html中,它们采用我打算发送到数据库的值。这是html:
<form method="post" action="admin.php">
Title:<input type="text" name="title" /><br />
Subtitle: <input type="text" name="subtitle" /><br />
Content:<textarea name="content"></textarea>
<input type="submit" name="submit" value="Post Blog Entry" />
</form>
与数据库的连接是:
<?php
$dbCon = mysqli_connect("localhost","root","","learnlearn");
if(mysqli_connect_errno())
{
echo "Failed to connect: " . mysqli_connect_error();
}
?>