首页 > 代码库 > bbs发帖核心代码

bbs发帖核心代码

<?php
//加载初始化文件
include ‘../init.php‘;

//加载数据库
include DIR_CORE.‘MYSQLDB.php‘;

//接受发帖页面传送的数据
$title = addslashes(strip_tags(trim($_POST[title])));
$content = addslashes(strip_tags(trim($_POST[content])));

//判断数据的合法性
if(empty($title) || empty($content)){
    header("refresh:2;url=./publish.php");
    die("标题或内容不能为空!请重新填写!");
}

//数据入库
//create table publish(
//    pub_id int unsigned primary key auto_increment comment ‘主键ID‘,
//    pub_title varchar(50) not null comment ‘帖子标题‘,
//    pub_content text not null comment ‘帖子内容‘,
//    pub_owner varchar(20) not null comment ‘发帖作者‘,
//    pub_time int unsigned not null comment ‘发帖时间‘,
//    pub_hits int unsigned not null comment ‘浏览次数‘
//);
$owner = "游客";
$time = time();

$sql = "insert into publish values(null,‘$title‘,‘$content‘,‘$owner‘,$time,default)";

$result = my_query($sql);
if($result){
    //执行成功
    header("location:./list_father.php");
}else{
    header("refresh:2;url=./publish.php");
    die("发生未知错误!发帖失败,请重新发帖");
}


bbs发帖核心代码