码迷,mamicode.com
首页 > 其他好文 > 详细

登陆主页面的制作

时间:2017-02-19 18:28:25      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:ati   操作   span   [1]   window   root   删除   inpu   ade   

第一个页面login.php

<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="button" value="登陆" /></div>
</form>

 

第二个页面chuli.php

<?php
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];

$db=new MySQLi("localhost","root","root","dbname");
//$sql="select count(*) from users where uid=‘$uid‘ and pwd=‘[$pwd]‘";能注入攻击,不采用
$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");       //(1)
    echo"<script>window.location = ‘main.php‘</script>";
    }       //(2)两种皆可
    else
    {
    echo"用户名或密码错误";
    }


?>

1、注意$sql语句和判断语句的写法

2、两种跳转页面的方式

 

 

第三个页面main.php

<table border="1" width="100%" cellpadding="0" cellspacing="0">

    <tr>
        <td>号码</td>
        <td>姓名</td>
        <td>性别</td>
        <td>生日</td>
        <td>职称</td>
        <td>部门</td>
        <td>操作</td>
    </tr>
<?php
$db=new MySQLi("localhost","root","root","dbname");
$sql="select * from teacher";
$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>{$attr[5]}</td>
        <td><a onclick=\"return confirm(‘确定要删除吗?‘)\" href=‘shanchu.php?code={$attr[0]}‘>删除</a></td>
    </tr>";
        }
    }

?>
</table>

1、性别处理时的写法

2、民族处理时从另外一个表格中再查内容

3、转义字符的应用(本篇onclick语句中单双引号的冲突)

 

 

第四个页面shanchu.php

<?php

$code=$_GET["code"];

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

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

?>

 

登陆主页面的制作

标签:ati   操作   span   [1]   window   root   删除   inpu   ade   

原文地址:http://www.cnblogs.com/gaobint/p/6416178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!