php实现一个留言板

www/test/mess文件夹下的两个文件:index.php和mess.db

其实现的一个简单版本:

index.php

<?php
//接收表单数据
$str = $_GET['mname']."<hr>";
file_put_contents("mess.db" , $str , FILE_APPEND);
?>
<!DOCTYPE html>
<html>
<head>
	<!--meta charset="UTF-8"-->
	<title>mess</title>
</head>
<body>
	<h2>文件留言板</h2>
	<hr>
	<form action="index.php">
		<h2>请留言:</h2>
		<textarea name="mname" id="" cols="100" rows="10"></textarea>
		<br>
		<input type="submit" value="send">
	</form>
	<h2>看留言:</h2>
	<?php
		readfile("mess.db");
	?>
</body>
</html>

将index分解成两文件index.php和rev.php

index.php

<!DOCTYPE html>
<html>
<head>
	<!--meta charset="UTF-8"-->
	<title>mess</title>
</head>
<body>
	<form action="rev.php" method="post">
		<h2>请留言:</h2>
		<textarea name="mname" id="" cols="100" rows="10"></textarea>
		<br>
		<input type="submit" value="send">
	</form>
	<h2>看留言:</h2>
	<?php
		echo file_get_contents("mess.db");
	?>
</body>
</html>
rev.php

<?php
//header('content-type:text/html;charset=utf-8');
$filename = "mess.db";
$str = $_POST['mname'];
if(!empty($str)) {
	$str .= "<hr>";
	file_put_contents($filename,$str,FILE_APPEND);
	echo "<script>location='index.php'</script>";
} 
else {
	echo "<script>alert('留言不能为空!')</script>";
	echo "<script>location='index.php'</script>";
}
?>



<html> <head> <title>留言板设计</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> <!-- body,td,th { font-size: 14px; color: #003399; } .xs{ font-size:12px} --> </style></head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="images/pub_01.gif" style="background-repeat:repeat-x"> <!-- ImageReady Slices (留言板设计(参考)副本.jpg) --> <form name="form1" method="post" action="add.asp"> <table width="600" height="500" border="0" align="center" cellpadding="0" cellspacing="0" id="__01"> <tr> <td width="36" height="500" rowspan="6"> </td> <td height="35" colspan="4"> </td> <td width="50" height="500" rowspan="6"> </td> </tr> <tr> <td colspan="4"><img src="images/pub_04.gif" width="514" height="69" alt=""></td> </tr> <tr> <td width="19" rowspan="4"><img src="images/pub_05.gif" width="19" height="396" alt=""></td> <td colspan="3"><img src="images/pub_06.gif" width="495" height="22" alt=""></td> </tr> <tr> <td><img src="images/pub_07.gif" width="49" height="321" alt=""></td> <td width="317" height="321" background="images/2_02.gif"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="17" colspan="4"> </td> </tr> <tr> <td width="61" height="30">昵称:</td> <td width="235" height="30" colspan="2"><input type="text" name="nc" style="width:120px; height:25px; border:solid #000000 1px;"></td> <td width="21" height="30"> </td> </tr> <tr> <td width="61" height="30">标题:</td> <td height="30" colspan="2"><input type="text" name="bt" style="width:180px; height:25px; border:solid #000000 1px;"></td> <td height="30"> </td> </tr> <tr> <td height="135" valign="middle">内容:</td> <td height="135" colspan="2" valign="middle"><textarea name="nr" cols="30" rows="10" style="border:solid #000000 1px;"></textarea></td> <td height="135"> </td> </tr> <tr> <td height="30"> </td> <td height="30" align="center"><input type="image" name="imageField" src="images/2_05.gif">  <a href="#"><img src="images/2_07.gif" width="62" height="33" border="0"></a></td> <td align="center" class="xs"><a href="view.asp">显示留言</a></td> <td height="30"><a href="view.asp"></a></td> </tr> </table></td> <td><img src="images/pub_09.gif" width="129" height="321" alt=""></td> </tr> <tr> <td colspan="3"><img src="images/pub_10.gif" width="495" height="22" alt=""></td> </tr> <tr> <td height="31" colspan="3"> </td> </tr> </table> </form> <!-- End ImageReady Slices --> </body> </html> <script language="vbscript"> function biaodan() dim usernc,userbt,usernr usernc=form1.nc.value userbt= form1.bt.value usernr=form1.nr.value if len(trim(usernc))<6 then alert("你输入的昵称有误!") biaodan=false exit function else if userbt="" then alert("你输入的标题有误!") biaodan=false exit function else if usernr="" then alert ("你输入的内容有误!") biaodan=false exit function end if end if end if end function sub quxiao() form1.nc.value="" form1.bt.value="" form1.nr.value="" end sub </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值