当前位置:首页 > 综合实例 > 列表

php access 留言板程序

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-11 20:45:39 浏览: 评论:0 

php access 留言板程序,这里不是php与mysql的留言板程序,而是一款简单实用的php access 留言板程序,利用了adodb来连接access数据库,代码如下:

  1. error_reporting(0); 
  2. $conn = new com("adodb.connection");  
  3. $conn->open("driver={microsoft access driver (*.mdb)}; dbq=" . realpath("db.mdb ")); 
  4. $rs=new com("adodb.recordset"); 
  5. $abc = $_get["abc"]; $webn = $_post["webn"]; $name = $_post["name"]; $pws = $_post["pws"]; $newpws = $_post["newpws"]; 
  6. $rs->open("select * from [web]",$conn,1,1); 
  7. $adminname = $rs->fields(1)->value; 
  8. $adminpws = $rs->fields(2)->value; 
  9. $ll = $rs->fields(3)->value; 
  10. $webname = $rs->fields(4)->value; 
  11. $rs->close(); 
  12. $admincookie = $adminname; 
  13. $conn->execute("update [web] set [ll] = '$ll'+1"); //$rs->close(); 
  14. ?> 
  15. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
  16. <html xmlns="http://www.111cn.net/1999/xhtml"> 
  17. <head> 
  18. <meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
  19. <title><? echo $webname ?></title> 
  20. <style type="text/css"> 
  21. <!-- 
  22. body {font-size:14px; line-height:25px; margin:10px auto; padding:10px; width:680px; border:solid #8aa 1px;} 
  23. a {color:#008; text-decoration:none;} 
  24. a:hover {color:#f00; text-decoration:underline;} 
  25. hr {color:#8aa; height:1px;} 
  26. --> 
  27. </style> 
  28. </head> 
  29. <body> 
  30. <? 
  31. if ($abc=="admin"){ 
  32.  if ($name==$adminname && $pws==$adminpws){ 
  33.  setcookie("admin", $admincookie, time()+3600); header("location:./"); 
  34.  }else{echo "<script>alert('用户名或密码错误!');history.back();</script>";} 
  35. } 
  36. if ($abc=="exit"){ 
  37. setcookie("admin", "", time()-3600); header("location:./"); 
  38. } 
  39. if ($abc=="editadmin"){ 
  40.  if (!$webname || !$name || !$pws){ 
  41.  echo "<script>alert('留言本、用户名、原密码不能为空!');history.back();</script>"; 
  42.  } 
  43.  if ($pws!=$adminpws){ 
  44.  echo "<script>alert('愿密码错误!');history.back();</script>"; 
  45.  } 
  46.  if($newpws!=""){ 
  47.  $conn->execute("update [web] set [webname] = '$webname' , [name] = '$name' , [pws] = '$newpws'"); 
  48.  $conn->close(); //$conn=null;  
  49.  echo "<script>alert('修改成功,请重新登录!');location='?abc=exit';</script>"; 
  50.  }else{ 
  51.  $conn->execute("update [web] set [webname] = '$webn' , [name] = '$name'"); 
  52.  $conn->close(); //$conn=null;  
  53.  echo "<script>alert('修改成功!');location='./';</script>"; 
  54.  } 
  55. } 
  56. ?> 
  57. <b>【 <a href="./"><? echo $webname ?></a> 】</b> 
  58. <a href="">管理</a> <? if (isset($_cookie["admin"])){ ?> <a href="">修改资料</a> <a href="">安全退出</a><? ;} ?> 
  59. <? if ($abc=="user" && !isset($_cookie["admin"])){ ?> 
  60.  <form method="post" action=""> 
  61.   用户名:<input name="name" type="text" value=""/> 
  62.   密码:<input name="pws" type="password" value=""/> 
  63.   <input name="add" type="submit" value="确定" /> 
  64.  </form> 
  65. <? ;} ?> 
  66. <? if ($abc=="edituser"){ ?> 
  67.  <form method="post" action=""> 
  68.   留言本:<input name="webn" type="text" value="<? echo $webname; ?>" size="80"/> 
  69.   <br /> 
  70.   用户名:<input name="name" type="text" value="<? echo $admincookie; ?>"/> 
  71.   原密码:<input name="pws" type="password" value=""/> 
  72.   新密码:<input name="newpws" type="password" value=""/> 
  73.   <input name="add" type="submit" value="确定" /> 
  74.  </form> 
  75. <? ;} ?> 
  76. <hr/> 
  77. <? 
  78. $id=$_get['id']; 
  79. $sj=date('y-m-d'); 
  80. if($abc=="add"){ 
  81.  $nr=$_post['nr']; 
  82.  $ip=getenv("remote_addr"); 
  83.  if (!$nr){ 
  84.  echo "<script>alert('留言不能为空!');history.back();</script>"; 
  85.  }else{ 
  86.  $conn->execute("insert into [txt] (nr,sj) values ('$nr','$sj')"); 
  87.  } 
  88.  echo "<script>alert('操作成功!');location='./';</script>"; 
  89.  $conn->close(); $conn=null; 
  90. } 
  91.  
  92. if($abc=="del"){ 
  93.  $conn->execute("delete from [txt] where [id]=".$id); 
  94.  $conn->close(); $conn=null; header("location:./"); 
  95. } 
  96. if($abc=="edit"){ 
  97.  $nr=$_post['nr']; 
  98.  $hf=$_post['hf']; 
  99.  $conn->execute("update [txt] set [nr] = '$nr' , [hf] = '$hf' where [id]=".$id); 
  100.  $conn->close(); $conn=null; header("location:./"); 
  101. } 
  102.  
  103. $zd=$_get['zd'];  
  104. if($zd!=""){ 
  105.  if($zd=="0")$zd=1; else $zd=0; 
  106.  $conn->execute("update [txt] set [zd] = '$zd' where [id]=".$id); 
  107.  $conn->close(); $conn=null; header("location:./"); 
  108. } 
  109. ?> 
  110. <center> 
  111. <form method="post" action=""> 
  112. <textarea name="nr" cols="88" rows="8" style="line-height:25px;"></textarea><br /><br /> 
  113. <input name="add" type="submit" value="发表留言" /> 
  114. </form> 
  115. </center> 
  116. <hr/> 
  117.  
  118. <? 
  119. //分页 
  120. $rs->open("select * from [txt] order by [zd] desc, [sj] desc",$conn,1,3); 
  121. $rs->pagesize=5; 
  122. $page=trim($_get['page']); 
  123. if($page=="" || is_numeric(intval($page))<=0){$page=1;}else if(intval($page)>$rs->pagecount){$page=$rs->pagecount;} 
  124. $page=intval($page);  
  125.  if(!$rs->eof||$rs->bof){ 
  126.   $rs->absolutepage=$page; $mypagesize=$rs->pagesize; $i=$rs->recordcount()-($page-1)*$rs->pagesize;   
  127.   while(!$rs->eof && $mypagesize>0 && $i>=$rs->recordcount()-1-$rs->pagesize*$page){  
  128.    $id = $rs->fields(0)->value; 
  129.    $nr = $rs->fields(1)->value; 
  130.    $hf = $rs->fields(2)->value; 
  131.    $sj = $rs->fields(3)->value; 
  132.    $zd = $rs->fields(4)->value; 
  133. ?> 
  134. <div style="border:#eee solid 1px; background:#f8f8f8; padding:0 10px;"> 
  135. <div style="float:left;"> 
  136. <? if ($zd!=0) echo "【 <font color='#008800'>置顶</font> 】"; else echo "id.".$i; ?> 
  137. <? if ($_cookie["admin"]==$admincookie){ ?>  
  138. 操作:<a href=''><? if ($zd==0) echo "置顶"; else echo "取消置顶"; ?></a> | 
  139. <a href=''>修改/回复</a> | 
  140. <a href=''>删除</a> 
  141. <? ;} ?> 
  142. </div> 
  143. <div style="float:right;"> 
  144. date:<? echo $sj; ?> 
  145. </div> 
  146. <div style="clear:both"></div> 
  147. </div> 
  148. <hr/> 
  149. <? if ($abc=="hf" && $id==$_get['id']){ ?> 
  150.  <form method="post" action="" id="<? echo $id ?>"> 
  151.  留言:<textarea name="nr" cols="80" rows="8" style="line-height:25px;"><? echo $nr; ?></textarea><br /> 
  152.  回复:<textarea name="hf" cols="80" rows="8" style="line-height:25px;"><? echo $hf; ?></textarea><br /> 
  153.  操作:<input name="add" type="submit" value="回复/修改" /> 
  154.  </form> 
  155. <? ;} ?>  
  156. <div style="margin:20px;"> 
  157. <? 
  158.  $nr = str_replace(" "," ".'<br/>',$nr);  
  159.  $nr = str_replace(" ",'&nbsp;',$nr);  
  160.  echo $nr."<br />"; 
  161. ?>  
  162. <? 
  163.  if ($hf!=""){ 
  164.   echo "<font color='#aa0000'>回复:"; 
  165.   $hf = str_replace(" "," ".'<br/>',$hf);  
  166.   $hf = str_replace("  ",'&nbsp;&nbsp;',$hf);  
  167.   echo $hf."</font>"; 
  168.  } 
  169. ?> 
  170. </div> 
  171. <hr/> 
  172. <? $rs->movenext; $mypagesize--; $i--; } } //分页循环 ?> 
  173. <center> 
  174. 留言数(<? echo $rs->recordcount(); ?>) 
  175. <a href="">首页</a> 
  176. <a href="">上页</a> 
  177. 第<? echo $page;?>/<? echo $rs->pagecount;?>页 
  178. <a href="">下页</a>//开源代码phpfensi.com 
  179. <a href="">尾页</a>&nbsp; 
  180. 访问量(<? echo $ll ?>) 
  181. </center> 
  182. <? $rs->close(); $rs=null; $conn->close(); $conn=null; ?> 
  183. </body> 
  184. </html> 

数据库结构:

id name pws ll webname

1 abc abc 4 abc 留言本 php+acc

Tags: php access 留言板程序

分享到: