最新PHP 简易留言板制作小实例

以下是三零网为大家整理的最新PHP 简易留言板制作小实例的文章,希望大家能够喜欢!

第一步:在mysql中新建数据库bbs 然后执行sql代码


CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;

 


 

第二步:新建conn.php


$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;

function htmtocode($content){
$content = str_replace("\n","
",str_replace(" "," ",$content));
return $content;
}
?>

 


 

第三步:新建add.php

 


include("conn.php");
if($_POST['submit'])
{
$sql="insert into message (id,user,title,content,lastdate)" .
"values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";

mysql_query($sql);
echo "";
}
?>





   
     
   
   
     
     
   
   
     
     
   
   
     
     
   
   
     
   
添加留言 查看留言 登陆
用户:
标题:
留言:

 


 

这一步做完了就可以实现添加留言了。

第四步显示留言 新建show.php
 


include("conn.php");

?>

$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
?>


   
   


   
   

  添加留言 查看留言 登陆
 


}
?>

 


 

内容保持原来的格式

首先 把conn.php里面加入
 


function htmtocode($content){
$content = str_replace("\n","
",str_replace(" "," ",$content));
return $content;

 


 

修改后的conn.php的格式如下


$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;

function htmtocode($content){
    $content = str_replace("\n", "
", str_replace(" ", " ", $content));
    return $content;
    }
?>

 


 

然后在输出页面把



 

改成


 


 

就可以了


转载来自:http://www.q3060.com/list3/list117/289.html