第三步就是php代码处理留言的信息合法性了,
<?php
require_once("inc/connect.php");
$myname =get_value('myname',post);
$mymail =get_value('mymail',post);
$mytel =get_value('mytel',post);
$mybook =get_value('mycontent',post);
//exit($mymail);
if(strlen($myname)>100 || strlen($myname)<1){alert('用户长度1-100','');}
if(!@preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",$mymail) || strlen($mymail)<6 ){alert('请输入正确的邮箱地址以便我们与你联系!','');}
if(!@preg_match("/\d{3}-\d{8}|\d{4}-\d{7}/",$mytel)){alert('请输入合法的电话如:0731-******','');}
$sql ="select * from tbn where gx_object='$myname' and gx_mail='$mymail'";
$result =mysql_query($sql);
if(mysql_num_rows($result)){
mysql_free_result($result);
alert('提示,你己提交留言,请不要重复提交!','');
}
$sql ="Insert into tbn(gx_content,gx_time,gx_tel,gx_mail,gx_object) value('$mybook','".date('y-m-d')."','$mytel','$mymail','$myname')";
mysql_query($sql) or die(alert('你的留言中有非法数据!',''));
alert('提示:留言成功',$_SERVER['HTTP_REFERER']);
?>
最四步就是显示留言了.
<?php
include("../inc/connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="style/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 {color: #000000}
.STYLE2 {color: #0000FF}
-->
</style>
<script>
<!--
function all_(str){
var box_l = document.getElementsByName("box_x[]").length;
for(var j = 0 ; j < box_l ; j++){
document.getElementsByName("box_x[]")[j].checked = str;
}
}
--></script>
</head>
<body>
<table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" style="margin-top:20px; border:1px solid #9abcde;">
<tr>
<td height="25" colspan="3" background="skins/top_bg.gif"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<form id="form2" name="form2" method="post" action="?"> <tr>
<td width="100%">你正在管理留言信息... </td>
<td width="0%" align="right">
<label></label><label></label></td>
</tr></form>
</table></td>
</tr> <form id="form1" name="form1" method="post" action="menu_sava.php?action=allbook">
<td width="4%"></tr>
<?php
$result =mysql_query("select * from tbn");
$pagecount=1;
$order=1;
if(isset($_POST['key'])){
$key=str_replace("'","*",$_POST['key']);
}else if(isset($_GET['key'])){
$key=str_replace("'","*",$_GET['key']);
}else{
$key='';
}
$total="select * from tbn";
$sql="select * from tbn";
if(!empty($key) && !is_null($key) && strlen($key)>2 && strlen($key)<50 ){
$total.=" where gx_title like '%$key%' ";
$sql.=" where gx_title like '%$key%' ";
}
$result=mysql_query($total) or die('fail1'.mysql_error());
$rs=mysql_fetch_array($result);
$rdcount=mysql_num_rows($result);
if($rdcount){
$pagesize=15;
$pagecount=($rdcount % $pagesize)?(int)($rdcount / $pagesize)+1:$rdcount/$pagesize;//统计总页面
$page=isset($_GET['page'])?$_GET['page']:1;//取得当前页面
$start=($page>=1 && $page<=$pagecount)?$start=$pagesize*($page-1):$start=1;//取得超始记录
$order=isset($_GET['order'])?$_GET['order']:4;
$sql.=" order by id desc limit $start,$pagesize";
$resulte=mysql_query($sql) or die('fail'.mysql_error());
while ($rs =mysql_fetch_array($resulte) ){
?> <tr>
<td height="25" colspan="3" align="left" valign="middle" background="images/main_bg.gif" class="td_heng" style="padding-right:5px;">
<input type="checkbox" name="box_x[]" id="box_x[]" value="<?php echo $rs[0];?>" />
标题:<?php echo $rs['gx_title']?>
作者:<?php echo $rs['gx_object']?>
电话:<?php echo $rs['gx_tel']?>
时间:<?php echo $rs['gx_time']?>
邮箱:<?php echo $rs['gx_mail']?></td>
<tr onMouseOver="this.style.background='#d7ebff'" onMouseOut="this.style.background='#ffffff'">
<td height="27" colspan="2" align="left" valign="middle" class="td_heng" style="padding:15px;">
<?php echo $rs['gx_content']?> </td>
<td width="7%" align="center" valign="bottom" class="td_heng"><a href="menu_sava.php?action=delguest&id=<?php echo $rs[0];?>" onclick="javascript:return confirm('确认删除?删除后无法恢复','','');">删除</a></td>
</tr>
<tr>
<td height="32" colspan="3"> </td>
</tr>
<?php
}
}
?>
<tr>
<td height="32" colspan="3" background="skins/top_bg.gif"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="34%"><input type="button" onclick="javascript:all_(true);" name="Submit" value="全选" />
<input type="button" onclick="all_(false);" name="Submit" value="反选" />
<input type="submit" onclick="javascript:return confirm('确认提醒:删除后无法还原!','','');" value='删除所选项' /></td>
<td width="66%" align="right" style="word-spacing:5px;">
<?php
$url ="?key=".rawurlencode($key)."&orderby=$order&page=";
pagelist(@$page,$pagecount,$rdcount,$url,@$pagesize);
?></td>
</tr>
</table></td>
</tr> </form>
</table>
</body>
</html>
注:原创文章转载请注明:www.111cn.net