php数据库操作代码
数据库名为reg,表名为member,字段名为username,password,regdate
<?php $link=@mysql_connect("localhost","root","root") or die ("连接数据库失败"); mysql_select_db("reg",$link) or die ("没有该数据库"); //以上两句为数据库连接语句 $sql="select * from member"; $rs=mysql_query($sql); $num=mysql_num_rows($rs); echo $num.'<br>'; //以上为测试显示记录条数 //以下为测试记录条数分页显示 $pagesize=3; $pagecount=($num-1)/$pagesize+1; $pagecount=(int)$pagecount; $pageno=$_GET["pageno"]; if($pageno<1) { $pageno=1; } if($pageno>$pagecount) { $pageno=$pagecount; } $startno=($pageno-1)*$pagesize; //以上计算页码数 $sql1="select * from member order by id desc limit $startno,$pagesize"; $rs1=mysql_query($sql1); while($rows=mysql_fetch_array($rs1)) { echo '用户名:'.$rows['username'].'<br>'; echo '密码:'.$rows['password'].'<br>'; echo '注册日期:'.$rows['regdate'].'<br><br>'; } ?> //以下显示页码号 <table width="450" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="278" bgcolor="#FFFFFF"><?php if($pageno==1) { ?> 首页 | 上页 | <a href="?pageno=<?php echo $pageno+1?>">下页</a> | <a href="?pageno=<?php echo $pagecount ?>">末页</a> <?php } else if($pageno==$pagecount) { ?> <a href="?pageno=1">首页</a> | <a href="?pageno=<?php echo $pageno-1?>">上页</a> | 下页 | 末页 <?php } else { ?> <a href="?pageno=1">首页</a> | <a href="?pageno=<?php echo $pageno-1?>">上页</a> | <a href="?pageno=<?php echo $pageno+1?>">下页</a> | <a href="?pageno=<?php echo $pagecount ?>">末页</a> <?php } ?> <?php for($i=1;$i<=$pagecount;$i++) { ?> <a href="?pageno=<?php echo $i?>"><?php echo $i?></a> <?php } ?></td> <td width="149" bgcolor="#FFFFFF"> <form name="frm" action="" method="get" style="margin:0px;"> <input type="text" name="pogeno" size="3" value="<?php echo $pageno?>" /> <input type="submit" value="go" /> </form></td> </tr> </table>
写入数据库语句
$sql="insert into member(id,username,password,regdate) values ('','$_POST[username]','$_POST[password]',now())"; $query=mysql_query($sql);
----------------
Lynx
The quieter you become,the more you are able to hear.