PHP開發 小型論壇教程之發布新帖-2

本頁面主要是處理從發布頁面addnew.php傳過來的數據,然後在進行資料庫存入

5.jpg

#程式碼如下

<?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>";
}
?>

現在我們已經可以發文了,快去試試吧


繼續學習
||
<?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>"; } ?>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!