PHP開發(fā) 小型論壇教程之發(fā)布新帖-2
本頁面主要是處理從發(fā)布頁面addnew.php傳過來的數(shù)據(jù),然後在進行資料庫存入
#程式碼如下
<?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"; // 創(chuàng)建連接 $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('發(fā)布成功');location.href='forums.php';</script>"; }else{ echo "<script>alert('好像有點小問題......');location.href='addnew.php';</script>"; } ?>
現(xiàn)在我們已經(jīng)可以發(fā)文了,快去試試吧