留言板最最常见的一种应用程序,在这里我就和大家一起来探讨下留言板的设计和实现。水平有限 功能不全 不要见怪
(在这里说明下 本人主板电池没电了所以系统时间是2001年12月31号 而且在截图的时候会看见2007-7-23的时间那也是错误的,完成时间是2007年7-22号下午。
在有系统还原后很多资料丢失,后面附的源代码可能和截图有点出入)
先让我们看看留言版的流程图,好让我们更好的了解如何设计他。
留言板的功能整体来说分为 :发布功能,回复功能,修改功能,删除功能,显示功能。
我们先来建立数据库表吧 ,为了省事我们没采用用户注册的 用户名 密码这样的传统流程,而是采用用户邮箱的形式来验证身份发表留言,管理留言也不是管理员的任务而是发布者的事情。在修改留言和删除留言那里通过发布者的邮箱密码来
这样就只要建立一个表就能完成我们的设计而不要建立用户表。
发布留言是留言版的首要功能,要详细考虑界面的设计,在这里我用最简单的做列子。
效果如图:
代码如下:
下面是操作处理代码:
-
- <!------ 传送增加留言数据的参数 add 给留言处理功能------>
- <form name="form1" method="post" action="message_process.php?check=add">
- <table width="481" border="1" cellpadding="0" cellspacing="0" align="center">
- <tr>
- <td>
- <table width="480" border="0" align="center" cellspacing="1" bordercolor="#000099" cellpadding="1">
- <tr>
- <td height="10" colspan="2" bgcolor="#006699">
- <div align="center"><font color="#EEEEEE" size="4">留言板</font></div>
- </td>
- </tr>
- <tr>
- <td height="30" bgcolor="#99CCFF">
- <div align="center">留言人</div>
- </td>
- <td height="30" bgcolor="#99CCFF">
- <input type="text" name="user" size="20">
- </td>
- </tr>
- <tr>
- <td height="23">
- <div align="center">e-mail</div>
- </td>
- <td height="23">
- <input type="text" name="email" size="36">
- </td>
- </tr>
- <tr>
- <td height="23" bgcolor="#99CCFF">
- <div align="center">留言主题</div>
- </td>
- <td height="23" bgcolor="#99CCFF">
- <input type="text" name="title" size="36">
- </td>
- </tr>
- <tr>
- <td height="80">
- <div align="center">留言内容</div>
- </td>
- <td height="80">
- <p>
- <textarea name="content" rows="10" cols="35"></textarea>
- <br>
- </p>
- </td>
- </tr>
- <tr>
- <td height="25" colspan="2" bgcolor="#006699">
- <div align="center">
- <input type="reset" name="Reset" value="清除重填">
- <input type="submit" name="Submit" value="送出留言">
- </div>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </form>
- <?
- include("db_conn.php");
- include("db_func.php");
- function ChangWord($NewWord){
- $NewWord=str_replace("","<br>",$NewWord);
- $NewWord=ereg_replace("[']+", "`", $NewWord);
- return $NewWord;
- }
- $time = date("Y-m-d g:i:s");
- $ip = $REMOTE_ADDR;
- if ($check==add)
- {
- $SQLStr = "INSERT INTO message (m_title, m_content, m_time, m_user, m_mail, m_pass, m_ip) ";
- $SQLStr .= " VALUES('$title', '" . ChangWord($content) . "', '$time', '$user', '$email', '$pass', '$ip') ";
- $message = "增加留言完成!";
- }
- if ($check==del)
- {
- include("idcheck.php");
- $SQLStr = "DELETE FROM message WHERE m_id = $m_id";
- $message = "删除留言完成!";
- }
- if ($check==upd)
- {
- include("idcheck.php");
- $SQLStr = "UPDATE message SET m_title='$title', m_content='" . ChangWord($content) . "', m_time='$time', ";
- $SQLStr .= "m_mail='$email', m_ip='$ip' WHERE m_id = '$m_id'";
- $message = "更新留言完成!";
- }
- db_query($SQLStr);
- ?>
- <script>
- alert("<?php echo $message; ?>");
- location.href = "message_list.php?p=0";
- </script>