PHP实现的迷你漂流瓶
本文实例讲述了PHP实现的迷你漂流瓶。分享给大家供大家参考。具体如下:
mysql.php:
<?php mysql_connect('127.0.0.1','root','wjy123')ordie('exit(-1)'); mysql_select_db('floatbtn'); mysql_query('setnamesutf8');
pickbtn.php:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/> <title>ppicku</title> <styletype="text/css"> .btn{ font-family:"微软雅黑"; font-size:12px; color:#FFF; background-color:#369; border:1pxsolid#666; } .box{ font-family:"微软雅黑"; color:#369; font-size:12px; border:1pxsolid#369; } </style> </head> <body> <ahref='throwbtn.php'>发布信息</a> <formid="form1"name="form1"method="post"action="pickbtn.php"> <tablewidth="80%"border="0"> <?php @include('mysql.php'); if(isset($_REQUEST['new'])){ $q='SELECT*FROM`btn`'; $rs=mysql_query($q); $max=mysql_num_rows($rs); $rd=rand(1,$max); $q="select*from`btn`whereid={$rd}"; $rs=mysql_query($q); while($re=mysql_fetch_array($rs)){ ?> <tr> <tdclass="box"width="12%">ID:</td> <tdclass="box"width="88%"><?=$re['author']?></td> </tr> <tr> <tdclass="box">Text:</td> <tdclass="box"><?=$re['text']?></td> </tr> <tr> <tdclass="box">Date:</td> <tdclass="box"><?=$re['date']?></td> </tr> <pclass="box">已读标记<?=$re['flag']?></p> </table> <?php $q="update`btn`setflag=1whereid={$re['id']}"; mysql_query($q); } } ?> <inputclass="btn"name="new"type="submit"value="截取"/> </form> </body> </html>
throwbtn.php:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/> <title>微软雅黑</title> <styletype="text/css"> .btn{ font-family:"微软雅黑"; font-size:12px; color:#FFF; background-color:#369; border:1pxsolid#666; } .box{ font-family:"微软雅黑"; color:#369; font-size:12px; border:1pxsolid#369; } .box1{ font-family:"微软雅黑"; font-size:12px; color:#369; width:800px; border:1pxsolid#666; } </style> </head> <body> <ahref='pickbtn.php'>截取信息</a> <?php @include('mysql.php'); if(isset($_REQUEST['send'])){ echo'PublishSuccessed!<br>'; $author=$_REQUEST['author']; $text=$_REQUEST['text']; $date=date('Y-m-dh:m:s'); if(!(null==trim($author))&&!(null==trim($text))){ $q="insertinto`btn`(`id`,`author`,`text`,`date`,`flag`)values('','$author','$text','$date','0')"; mysql_query($q); } } ?> <formid="form1"name="form1"method="post"action="throwbtn.php"> <tablewidth="80%"border="0"> <tr> <thclass="box"width="110">ID</th> <tdclass="box"width="442"><inputclass="box1"type="text"name="author"/></td> </tr> <tr> <thclass="box">Text</th> <tdclass="box"><inputclass="box1"name="text"type="text"/></td> </tr> <tr> <thclass="box">Date</th> <tdclass="box"> <inputclass="box1"type="text"name="date"disabled="disabled"value="<?=date('Y-m-d')?>"/></td> </tr> </table> <divalign="center"><inputclass="btn"name="send"type="submit"value="SendMessage"/></div> </form> </body> </html>
希望本文所述对大家的php程序设计有所帮助。