PHP development...LOGIN

PHP development small forum tutorial publishing new posts-2

This page mainly processes the data passed from the release page addnew.php, and then stores it in the database

5.jpg

##The code is as follows

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$author=$_POST['author'];
$title=$_POST['title'];
$content=$_POST['content'];
$last_post_time=date("Y-m-d H:i:s");
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //设定字符集
$sql="insert into tiopic(author,title,content,last_post_time) values('$author','$title','$content','$last_post_time')";
$que=mysqli_query($conn,$sql);
if($que){
    echo "<script>alert('发布成功');location.href='forums.php';</script>";
}else{
    echo "<script>alert('好像有点小问题......');location.href='addnew.php';</script>";
}
?>


Now we can publish posts, go and try it


Next Section

<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $author=$_POST['author']; $title=$_POST['title']; $content=$_POST['content']; $last_post_time=date("Y-m-d H:i:s"); $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "mybbs"; // 创建连接 $conn = mysqli_connect($servername, $username, $password, $dbname); mysqli_set_charset($conn,'utf8'); //设定字符集 $sql="insert into tiopic(author,title,content,last_post_time) values('$author','$title','$content','$last_post_time')"; $que=mysqli_query($conn,$sql); if($que){ echo "<script>alert('发布成功');location.href='forums.php';</script>"; }else{ echo "<script>alert('好像有点小问题......');location.href='addnew.php';</script>"; } ?>
submitReset Code
ChapterCourseware