PHP開發 小型論壇教程之添加論壇-2

建立save_forum.php 檔案

#本頁面是處理從新增頁面add_forum.php提交過來的資料

save.jpg

#程式碼如下

header("content-type:text/html;charset=utf8");
$forum_name=$_POST["forum_name"];
$forum_description=$_POST["forum_description"];
$Subject=$_POST['Subject'];
$time=date("Y-m-d H:i:s");
$conn=mysqli_connect("localhost","root","root","mybbs");
mysqli_set_charset($conn,"utf8");
$sql="insert into  forums (forum_name,forum_description,subject,last_post_time) VALUES ('$forum_name','$forum_description','$Subject','$time')";
$que=mysqli_query($conn,$sql);
if($que){
    echo "<script>alert('添加成功');location.href='index.php';</script>";
}else{
    echo "<script>alert('添加失败,请稍后再试');location.href='add_forum.php';</script>";
}
?>


繼續學習
||
<?php header("content-type:text/html;charset=utf8"); $forum_name=$_POST["forum_name"]; $forum_description=$_POST["forum_description"]; $Subject=$_POST['Subject']; $time=date("Y-m-d H:i:s"); $conn=mysqli_connect("localhost","root","root","mybbs"); mysqli_set_charset($conn,"utf8"); $sql="insert into forums (forum_name,forum_description,subject,last_post_time) VALUES ('$forum_name','$forum_description','$Subject','$time')"; $que=mysqli_query($conn,$sql); if($que){ echo "<script>alert('添加成功');location.href='index.php';</script>"; }else{ echo "<script>alert('添加失败,请稍后再试');location.href='add_forum.php';</script>"; } ?>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!