PHP开发 小型论坛教程之发布...LOGIN

PHP开发 小型论坛教程之发布新帖-2

创建addnew_post.php 文件

本页面主要是处理从发布页面addnew.php传过来的数据,然后在进行数据库存入

11.jpg

代码如下

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //设定字符集
$author=$_POST['author'];
//print_r($author);
//die;
$title=$_POST['title'];
$content=$_POST['content'];
$last_post_time=date("Y-m-d H:i:s");
$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>";
}
?>


下一节
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "mybbs"; // 创建连接 $conn = mysqli_connect($servername, $username, $password, $dbname); mysqli_set_charset($conn,'utf8'); //设定字符集 $author=$_POST['author']; //print_r($author); //die; $title=$_POST['title']; $content=$_POST['content']; $last_post_time=date("Y-m-d H:i:s"); $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>"; } ?>
提交重置代码
章节课件