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

PHP实现的迷你漂流瓶

发布:smiling 来源: PHP粉丝网  添加日期:2021-06-14 15:11:28 浏览: 评论:0 

这篇文章主要介绍了PHP实现的迷你漂流瓶,涉及php针对数据库的读写操作及随机数等操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下。

本文实例讲述了PHP实现的迷你漂流瓶,分享给大家供大家参考,具体如下:

mysql.php:

  1. <?php 
  2. mysql_connect('127.0.0.1','root','wjy123') or die('exit(-1)'); 
  3. mysql_select_db('floatbtn'); 
  4. mysql_query('set names utf8'); 

pickbtn.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  6. <title>ppick u</title> 
  7. <style type="text/css"> 
  8. .btn { 
  9.   font-family: "微软雅黑"; 
  10.   font-size: 12px; 
  11.   color: #FFF; 
  12.   background-color: #369; 
  13.   border: 1px solid #666; 
  14. } 
  15. .box { 
  16.   font-family: "微软雅黑"; 
  17.   color: #369; 
  18.   font-size: 12px; 
  19.   border: 1px solid #369; 
  20. } 
  21. </style> 
  22. </head> 
  23. <body> 
  24. <a href='throwbtn.php'>发布信息</a> 
  25. <form id="form1" name="form1" method="post" action="pickbtn.php"> 
  26. <table width="80%" border="0"> 
  27. <?php 
  28. @include('mysql.php'); 
  29. if(isset($_REQUEST['new'])){ 
  30. $q = 'SELECT * FROM `btn`'; 
  31. $rs = mysql_query($q); 
  32. $max = mysql_num_rows($rs); 
  33. $rd = rand(1,$max); 
  34. $q = "select * from `btn` where id = {$rd}"; 
  35. $rs = mysql_query($q); 
  36. while($re = mysql_fetch_array($rs)){ 
  37. ?> 
  38.  <tr> 
  39.   <td class="box" width="12%">ID : </td> 
  40.   <td class="box" width="88%"><?=$re['author']?></td> 
  41.  </tr> 
  42.  <tr> 
  43.   <td class="box" >Text : </td> 
  44.   <td class="box"><?=$re['text'] ?></td> 
  45.  </tr> 
  46.  <tr> 
  47.   <td class="box">Date : </td> 
  48.   <td class="box"><?=$re['date']?></td> 
  49.  </tr> 
  50.  <p class="box">已读标记 <?=$re['flag']?></p> 
  51. </table> 
  52. <?php 
  53. $q = "update `btn` set flag = 1 where id = {$re['id']}"; 
  54. mysql_query($q); 
  55. } 
  56. } 
  57. ?> 
  58. <input class="btn" name="new" type="submit" value="截取"/> 
  59. </form> 
  60. </body> 
  61. </html> 

throwbtn.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  6. <title>微软雅黑</title> 
  7. <style type="text/css"> 
  8. .btn { 
  9.   font-family: "微软雅黑"; 
  10.   font-size: 12px; 
  11.   color: #FFF; 
  12.   background-color: #369; 
  13.   border: 1px solid #666; 
  14. } 
  15. .box { 
  16.   font-family: "微软雅黑"; 
  17.   color: #369; 
  18.   font-size: 12px; 
  19.   border: 1px solid #369; 
  20. } 
  21. .box1 { 
  22.   font-family: "微软雅黑"; 
  23.   font-size: 12px; 
  24.   color: #369; 
  25.   width: 800px; 
  26.   border: 1px solid #666; 
  27. } 
  28. </style> 
  29. </head> 
  30. <body> 
  31. <a href='pickbtn.php'>截取信息</a> 
  32. <?php 
  33. @include('mysql.php'); 
  34. if(isset($_REQUEST['send'])){ 
  35.   echo 'Publish Successed !<br>'; 
  36.   $author = $_REQUEST['author']; 
  37.   $text = $_REQUEST['text']; 
  38.   $date = date('Y-m-d h:m:s'); 
  39.   if(!(null == trim($author)) && !(null == trim($text))) { 
  40.   $q = "insert into `btn`(`id`,`author`,`text`,`date`,`flag`) values('','$author','$text','$date','0')"; 
  41.   mysql_query($q); 
  42.   } 
  43. } 
  44. ?> 
  45. <form id="form1" name="form1" method="post" action="throwbtn.php"> 
  46. <table width="80%" border="0"> 
  47.  <tr> 
  48.   <th class="box" width="110">ID</th> 
  49.   <td class="box" width="442"><input class="box1" type="text" name="author" /></td> 
  50.  </tr> 
  51.  <tr> 
  52.   <th class="box" >Text</th> 
  53.   <td class="box"><input class="box1" name="text" type="text" /></td> 
  54.  </tr> 
  55.  <tr> 
  56.   <th class="box">Date</th> 
  57.   <td class="box"> 
  58.    <input class="box1" type="text" name="date" disabled="disabled" value="<?=date('Y-m-d')?>" /></td> 
  59.  </tr> 
  60. </table> 
  61. <div align="center"><input class="btn" name="send" type="submit" value="Send Message"/></div> 
  62. </form> 
  63. </body> 
  64. </html> 

希望本文所述对大家的php程序设计有所帮助。

Tags: PHP迷你漂流瓶

分享到: