1. 程式人生 > >php留言板程序

php留言板程序

files 程序 css border inpu -s note fop !=

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

先創建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留言板程序