<select>
<?php
$db=new MySQLi("localhost","root","3177389","my test");
!mysqli_connect_error() or die("连接失败!");
$sql="select*from Nation";
$result=$db->query($sql);
$attr=$result->fetch_all();
for($i=0;$i<count($attr );$i++)
{
list($code,$name)=$attr[$i];
echo "<option value='{$code}'>{$name}</option>";
}
?>
</select>
<?php
//造连接对象
$db=new MySQLi("localhost","root","3177389","my test");
//判断是否出错
!mysqli_connect_error()or die ("连接失败!");
//写sql语句
$sql="select *from Info";
//执行sql语句
$result=$db->query($sql);
//处理查询数据并显示
echo "<table width='100%' border='1' cellpadding='0' cellpadding='0'>";
echo "<tr><td>代号</td><td>姓名</td><td>性别</td><td>民族</td ><td>生日</td></tr>";
while($row=$result->fetch_row())
{
$sex=$row[2]?"男":"女";
$name =ShowNation($db,$row [3]);
echo "<tr><td>{$row[0]}</td><td>{$row[1]}</td><td>{$sex}</td><td>{$name}</td ><td>{$row[4]}</td></tr>";
}
echo "</table >";
function showNation ($db,$code)
{
$sql = "select Name from Nation where Code='{$code}'";
$result=$db->query($sql);
$jieguo =$result ->fetch_row();
return $jieguo[0];
}
?>
<form action="0324chili.php" method="post">
<div>
用户名:
<input type="text" name="zw" />
</div>
<div>
密码:
<input type="text" name="pwd" />
</div>
<div>
<input type="submit" value="登录" />
</div>
</form>
<?php
$uid=$_POST["zw"];
$pwd=$_POST["pwd"];
$db=new MySQLi("localhost","root","3177389","my test");
!mysqli_connect_error()or die ("连接失败!");
$sql="select count(*) from login where username='{$uid}' and password='{$pwd}'";
$resul=$db->query($sql);
$attr=$resul->fetch_row();
if($attr[0] == 1)
{
header("location:zhu.php");
}
else
{
header("location:denglu.php");
}