码迷,mamicode.com
首页 > Web开发 > 详细

php留言板程序

时间:2017-10-11 23:49:34      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:留言板   fread   replace   res   for   tar   else   mil   com   

===================

先创建note.php

<html>
<head><title>PHP留言本</title></head>
<style type="text/css">
<!--
.{ font-family: "宋体"; font-size: 9pt;}
-->
</style>
<body bgcolor=#cccccc>
<center><font style=" color=color:#cccccc;font-size:12pt">php留言本</font>
<form method="POST" action="result.php">
<table border=1 width=555>
<tr>
 <td width=20%>您的大名:
 </td>
 <td width=50%><input type=text name=nickname style=width:100%>
 </td>
</tr>
<tr>
 <td width=20%>电子邮件:
 </td>
 <td width=50%><input type=text name=email style=width:100%>
 </td>
</tr>
<tr >
 <td width=20%>留言:<br><br><br>
 </td>
 <td width=80%> <textarea name=notes  cols="70" rows="5" ></textarea>
 </td>
</tr>
<tr>
 <td width=20%> </td>
 <td width=80% align=center><input type="submit" name=submit value="确定"><input type="reset" value="重写"><input name=clear type="submit" value="清除" >

 </td>
</tr></table>
</form></table>
<table border=1 width=555>
<tr><td>
<hr width=550><?
$f = fopen("note.txt","r");
$msg = fread($f,filesize("note.txt"));
fclose($f);
print "$msg";
?></td>
</tr>
</table>
</center>

<p align=right><font style=" color=color:#cccccc;font-size:12pt">作者:<a href="mailto:dengfzj@126.com">业如</a><br>
主页:<a href="http://weibo.com/dengyr">微博</a></font>


</body>
</html>
然后创建

result.php

<html>
<head>
<style type="text/css">

</style>
<body bgcolor=#cccccc>

<table align=center border=0 width=555>  <tr>
<?php
//先判断是否清除
if($_POST["clear"]=="清除")
 {
 print "<td align=center><b><h1 ><font color=red>已清除!</font></h1></td><br><br>";
 $f=fopen("note.txt","w");
 fwrite($f,"");
 fclose($f);
 }
 else{
  if(($_POST["nickname"]&&$_POST["email"]&&$_POST["notes"])!=0)
  {
$t = date(Y年m月d日);
$note=str_replace("<","<",$_POST["notes"]);
$note=str_replace(">",">",$note);
$note=str_replace("
","<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",$note);
$main="<font color=#FF6600>网上大名:</font><a href=mailto:".$_POST

["email"].">".$_POST["nickname"]."</a>(".$t.")<br><font color=#FF6600>

留言:</font>".$note." <br><hr width=550>"; 
$f=fopen("note.txt","a");
fwrite($f,$main);
fclose($f);
print "<td align=center><b><h1 ><font color=red>成功!</font></h1></td><br><br>";
print "$main";
print "<b><font font-size=9pt color=#FF99FF>谢谢您的留言!</font><br>";
}
  else{
  if ($_POST["nickname"]=="")
  print "<b><font font-size=9pt color=#00CC00>您的大名?</font><br>";
  if($_POST["email"]=="")
  print "<b><font font-size=9pt color=#00CC00>您电子邮件?</font><br>";
  if($_POST["notes"]=="")
  print "<b><font font-size=9pt color=#00CC00>您没有要说的吗?</font><br>";
  print "<td align=center><b><h1 ><font color=red>请检查以上各项!</font></h1></td><br><br>";
  }
 
   }
?>  </tr>
</table>
<p><br></p>
<p><br></p>
<center><a href="note.php">返回</a></center>
<p><br></p>
<p align=right><font style=" color=color:#cccccc;font-size:12pt">作者:

<a href="mailto:dengfzj@126.com">业如</a><br>
主页:<a href="http://weibo.com/dengyr">微博</a></font>

</body>
</html>

ok代码结束了

php留言板程序

标签:留言板   fread   replace   res   for   tar   else   mil   com   

原文地址:http://www.cnblogs.com/dengfzj/p/7653364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!