代码如下:
lisjk.php:
<?php
$a=mysql_connect("localhost","root","")or die ("连接错误");
 mysql_select_db("bbs",$a)or die ("连接错误");
 mysql_query("set names 'utf-8'");
 
 function htmtocode($content){
$content = str_replace("\n","<br>",str_replace(" ", "&nbsp;", $content));
   return $content;
 }
//$content=str_replace("`","`",$content);
 //htmlspecialchars();
 
 ?>
2.php:
<?php
include("ljsjk.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 "<script language=\"javascript\">alert('发表成功');history.go(-1)</script>";}
include("4.php");
?>
<script language=javascript>
function CheckPost()
{
if (myform.user.value=="") {alert("请填写用户");
myform.user.focus();
return false;
}
if (myform.title.value.length<5) {
   alert("标题不能少于5个字符");
  myform.title.focus;
  return false;
}
if (myform.title.value=="") {
   alert("必须要填写留言内容");
  myform.content.focus();
  return false;
}}
</script><form action="2.php" method="post" name="myform" onsubmit="return CheckPost();">
用户:<input type="text"  size="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content"></textarea><br/>
<input type="submit" name="submit" value="发布留言" />
</form>
3.php:
<?phpinclude("ljsjk.php");
include("4.php");
$sql="select * from `message` order by id desc";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)) {

?>
<table width="500" border="0" align="center" cellpadding="5" bgcolor="#add3ef"> <tr bgcolor="#eff3ff"> <td>标题:<?= $row['title']?>   用户:<?= $row['user']?></td>
    </tr>
    <tr bgcolor="#ffffff">
    <td>内容:<?php
    echo htmtocode($row['content']);
    ?></td>
    </tr>
    </table>
    <?
}
?>4.php:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="images/css.css" rel="stylesheet" type="text/css">
<b><a href="2.php">添加留言</a> | <a href="3.php">浏览留言</a> | <a href="5.php">登陆</a></b>
<hr size="1">
5,php:
<?php
include("ljsjk.php");
if($_GET["out"]){
setcookie("cookie","out");
echo"<script language=\"javascript\">location.href='5.php';</script>";
}
if ($_POST["id"]=='admin') {
$pw=md5($_POST['pw']);
if ($pw=='e1bfd762321e409cee4ac0b6e841963c') {
setcookie("cookie","ok");
echo "<script language=\"javascript\">location.href='5.php';</script>";
}
}
include("4.php");
if ($_COOKIE['cookie']!='ok') {
?><SCRIPT language=javascript>
function Checklogin()
{
   if (myform.id.value=="")
    {
    alert("请填写登陆名");
    myform.id.focus();
    return false;
   }
    if (myform.pw.value=="") 
    {
    alert("密码不能为空");
    myform.pw.focus();
    return false;}
}
</SCRIPT>
<form action="" method="post" name="myform" onsubmit="return Checklogin();">
ID:  <input type="text" name="id" /><br>
PW: <input type="password" name="pw" />
<input type="submit" name="submit" value="登陆" />
</form>
<?php
}else{
?>
<a href='?out=login'>退出</a>
<?php
}
?>代码就是这些了求大神指正