首页 >后端开发 >php教程 >php针对数据库的读写操作及随机数等操作

php针对数据库的读写操作及随机数等操作

墨辰丷
墨辰丷原创
2018-06-08 11:59:051615浏览

本篇文章主要介绍php针对数据库的读写操作及随机数等操作,感兴趣的朋友参考下,希望对大家有所帮助。

具体如下:

mysql.php:

<?php
mysql_connect(&#39;127.0.0.1&#39;,&#39;root&#39;,&#39;wjy123&#39;) or die(&#39;exit(-1)&#39;);
mysql_select_db(&#39;floatbtn&#39;);
mysql_query(&#39;set names utf8&#39;);

pickbtn.php:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ppick u</title>
<style type="text/css">
.btn {
  font-family: "微软雅黑";
  font-size: 12px;
  color: #FFF;
  background-color: #369;
  border: 1px solid #666;
}
.box {
  font-family: "微软雅黑";
  color: #369;
  font-size: 12px;
  border: 1px solid #369;
}
</style>
</head>
<body>
<a href=&#39;throwbtn.php&#39;>发布信息</a>
<form id="form1" name="form1" method="post" action="pickbtn.php">
<table width="80%" border="0">
<?php
@include(&#39;mysql.php&#39;);
if(isset($_REQUEST[&#39;new&#39;])){
$q = &#39;SELECT * FROM `btn`&#39;;
$rs = mysql_query($q);
$max = mysql_num_rows($rs);
$rd = rand(1,$max);
$q = "select * from `btn` where id = {$rd}";
$rs = mysql_query($q);
while($re = mysql_fetch_array($rs)){
?>
 <tr>
  <td class="box" width="12%">ID : </td>
  <td class="box" width="88%"><?=$re[&#39;author&#39;]?></td>
 </tr>
 <tr>
  <td class="box" >Text : </td>
  <td class="box"><?=$re[&#39;text&#39;] ?></td>
 </tr>
 <tr>
  <td class="box">Date : </td>
  <td class="box"><?=$re[&#39;date&#39;]?></td>
 </tr>
 <p class="box">已读标记 <?=$re[&#39;flag&#39;]?></p>
</table>
<?php
$q = "update `btn` set flag = 1 where id = {$re[&#39;id&#39;]}";
mysql_query($q);
}
}
?>
<input class="btn" name="new" type="submit" value="截取"/>
</form>
</body>
</html>

throwbtn.php:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>微软雅黑</title>
<style type="text/css">
.btn {
  font-family: "微软雅黑";
  font-size: 12px;
  color: #FFF;
  background-color: #369;
  border: 1px solid #666;
}
.box {
  font-family: "微软雅黑";
  color: #369;
  font-size: 12px;
  border: 1px solid #369;
}
.box1 {
  font-family: "微软雅黑";
  font-size: 12px;
  color: #369;
  width: 800px;
  border: 1px solid #666;
}
</style>
</head>
<body>
<a href=&#39;pickbtn.php&#39;>截取信息</a>
<?php
@include(&#39;mysql.php&#39;);
if(isset($_REQUEST[&#39;send&#39;])){
  echo &#39;Publish Successed !<br>&#39;;
  $author = $_REQUEST[&#39;author&#39;];
  $text = $_REQUEST[&#39;text&#39;];
  $date = date(&#39;Y-m-d h:m:s&#39;);
  if(!(null == trim($author)) && !(null == trim($text))) {
  $q = "insert into `btn`(`id`,`author`,`text`,`date`,`flag`) values(&#39;&#39;,&#39;$author&#39;,&#39;$text&#39;,&#39;$date&#39;,&#39;0&#39;)";
  mysql_query($q);
  }
}
?>
<form id="form1" name="form1" method="post" action="throwbtn.php">
<table width="80%" border="0">
 <tr>
  <th class="box" width="110">ID</th>
  <td class="box" width="442"><input class="box1" type="text" name="author" /></td>
 </tr>
 <tr>
  <th class="box" >Text</th>
  <td class="box"><input class="box1" name="text" type="text" /></td>
 </tr>
 <tr>
  <th class="box">Date</th>
  <td class="box">
   <input class="box1" type="text" name="date" disabled="disabled" value="<?=date(&#39;Y-m-d&#39;)?>" /></td>
 </tr>
</table>
<p align="center"><input class="btn" name="send" type="submit" value="Send Message"/></p>
</form>
</body>
</html>

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

php针对当前编码的判断与对应的编码转换实现技巧

php使用MagickWand模块操作图片添加水印的方法

php使用历史记录功能

以上是php针对数据库的读写操作及随机数等操作的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn