登录主页面代码

<!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>

<h1>登录页面</h1>

<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="登录" /></div>
</form>

</body>
</html>
<?php
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];

$db = new MySQLi("localhost","root","123","mydb");

$sql = "select pwd from users where uid='{$uid}'";
$result = $db->query($sql);

$a = $result->fetch_row();

if(!empty($pwd) && $a[0]==$pwd)
{
    //跳转页面
    //header("location:main.php");
    echo "<script>window.location = 'main.php';</script>";
}
else
{
    echo "用户名或密码错误!";
}
<!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>

<h1>人员列表</h1>

<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 = "select * from info";
    $result = $db->query($sql);
    
    if($result)
    {
        while($attr = $result->fetch_row())
        {
            //对性别进行了处理
            $sex = $attr[2]?"男":"女";
            
            //对民族进行处理
            $sname = "select name from nation where code='{$attr[3]}'";
            $nresult = $db->query($sname);
            $aname = $nresult->fetch_row();
            $nation = $aname[0];
            
            
            echo "<tr>
        <td>{$attr[0]}</td>
        <td>{$attr[1]}</td>
        <td>{$sex}</td>
        <td>{$nation}</td>
        <td>{$attr[4]}</td>
        <td><a onclick=\"return confirm('确定要删除么?')\" href='shanchu.php?code={$attr[0]}'>删除</a></td>
    </tr>";
        }
    }
    
    ?>
    
</table>

</body>

</html>
<?php

$code = $_GET["code"];

$db = new MySQLi("localhost","root","123","mydb");
$sql = "delete from info where code='{$code}'";

if($db->query($sql))
{
    header("location:main.php");
}
else
{
    echo "删除失败";
}

 

posted @ 2017-02-19 16:42  周全264  阅读(414)  评论(0编辑  收藏  举报