数据访问的登陆界面
2024-09-21 03:40:39 207人阅读
登录界面的代码:
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml">
<
head
>
<
meta
http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title
>无标题文档</
title
>
</
head
>
<
body
>
<
form
action="chuli.php" method="post">
<
div
>用户名:<
input
type="text" name="uid" /></
div
>
<
div
>密码:<
input
type="password" name="pwd" /></
div
>
<
div
><
input
type="submit" value="http://www.mamicode.com/登录" /></
div
>
</
form
>
</
body
>
</
html
>
处理页面的php代码:
<?php $uid = $_POST["uid"]; $pwd = $_POST["pwd"];
//造连接对象 $db = new MySQLi("localhost","root","123","mydb");
//写SQL语句
$sql = "select password from login where username=‘{$uid}‘";
//执行SQL语句 $reslut = $db->query($sql);
$n = $reslut->fetch_row();
if($uid!="" && $pwd !="" ) { if($n[0]==$pwd) { header("location:main.php"); } else { echo "用户名或密码错误!"; } } else { echo "用户名密码不能为空"; }
登陆后跳转到的main界面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>生日</td> <td>操作</td> </tr> <?php //造连接对象 $db = new MySQLi("localhost","root","123","mydb"); //写SQL语句 $sql = "select * from info"; //执行SQL语句 $result = $db->query($sql); //读数据 $attr = $result->fetch_all(); foreach($attr as $v) { $sex = $v[2]?"男":"女"; //根据名族代号查询名族名称 $name = NationName($v[3]); echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$sex}</td><td>{$name}</td><td>{$v[4]}</td></tr>"; } //给一个民族代号,返回民族名称 function NationName($code) { //造连接对象 $db = new MySQLi("localhost","root","123","mydb"); //写SQL语句 $sql = "select name from nation where code=‘{$code}‘"; //执行SQL语句 $result = $db->query($sql); $attr = $result->fetch_row(); return $attr[0]; } ?> </table> </body> </html>
数据访问的登陆界面
turn attr xhtml1.0 type 登录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。
×
https://www.u72.net/daima/nn71u.html