原生PHP和MYSQL练习登陆验证和查询数据到表格
直接上代码吧
<?php header("Content-type: text/html; charset=utf-8"); //数据量链接 $conn=mysqli_connect("127.0.0.1",‘bc‘,"HGEAfZdSbaXHD5NA",‘test‘); //需求一 // 登陆验证密码 function checkuser($conn,$username,$password) { $res=0; $sql="select * from admin where username=‘".$username."‘"; $result=mysqli_query($conn,$sql); if($result) { $dinfo=mysqli_fetch_array($result);//取得一条记录 if($password==$dinfo[‘password‘]) { $res=1; } } return $res; } $username=‘admin‘; $password=‘123456‘; //使用方法 $res=checkuser($conn,$username,$password); echo $res; //需求二 //查询所有数据到表格 $sql="select * from admin"; $result=mysqli_query($conn,$sql); if($result) { $dinfo=mysqli_fetch_all($result);// echo "<table border=1><tr><td>序号</td><td>用户名</td><td>密码</td><tr>"; $i=1; foreach($dinfo as $k=>$v) { echo "<tr><td>".$i."</td><td>".$v[‘1‘]."</td><td>".$v[‘2‘]."</td></tr>"; $i++; } echo "</table>"; }
表结构和数据如下
效果如下
相关推荐
yifangs 2020-10-13
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23