知识点:
首先建立一个head.php文件
<head>
<mate http-equiv="Conter-Type" content="text/html;charset=gb2312">
<title></title>
<link href="images/css.css" rel="stylesheet" type="text/css">
<b><a href="add.php">添加留言</a> |<a href="list.php">浏览留言</a> | <a href="login.php">登陆</a> </b>
<hr size=1>
会显示这种页面
在add.php文件里加入include("head.php");此语句
add.php代码;
<?php
include("link.php");
if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)".
"value('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";
}
include("head.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.content.value=="")
{
alert("内容不能为空");
myform.content.focus();
return false;
}
}
</SCRIPT>
<form action="add.php" method="post" name="myform" οnsubmit="return CheckPost();">
用户:<input type="text" size="10" name="user"/><br>
标题: <input type="text" name="title" /><br>
内容:<textarea name="content"></textarea><br><br/>
<input type="submit" name="submit" value="发表留言"/>
</form>
建立conn.php文件用来实现显示空格,回车等替换功能
<?php
$conn = @ mysql_connect("localhost", "root", "123456") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
function htmtocode($content) {
$content = str_replace("\n", "<br>", str_replace(" ", " ", $content)); //把键盘输入的空格回车符号,转换为php代码能识别显示的符号
return $content;
}
//$content=str_replace("'","‘",$content);
//htmlspecialchars();
?>
建立登陆页面
<?php
include("link.php");
if($_GET[out]){
setcookie("cookie", "out");
echo "<script language=\"javascript\">location.href='login.php';</script>";
}
if($_POST[id]=='admin'){
$pw=md5($_POST[pw]);
if($pw=='e1bfd762321e409cee4ac0b6e841963c'){
setcookie("cookie", "ok");
echo "<script language=\"javascript\">location.href='login.php';</script>";
}
}
include("head.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" οnsubmit="return Checklogin();">
ID:<input type="text" name="id" /><br>
PW:<input type="password" name="pw" /> <input type="submit" name="submit" value="登陆"/>
</form>
<?
}else{
?>
<a href='?out=login'>退出</a>
<?
}
?>