简单的网页登录程序

在登录页面输入用户名和密码,是一个html页面

<!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="text" name="pwd" />    
    </div>
    <div>
        <input type="submit" value="登录" />
    </div>
    
</form>


</body>
</html>

运行如下:

点击登录按钮之后提交到chuili.php页面进行处理

<?php

$uid=$_POST["uid"];
$pwd=$_POST["pwd"];

    //造链接对象
    $db=new MySQLi("localhost","root","123456","xinjian");
    
    //判断是否出错
     !mysqli_connect_error() or die("链接失败");
          
     //写sql语句
     $sql="select count(*) from login where username ='{$uid}' and password='{$pwd}'";
    
    //执行sql语句
    $result =$db->query($sql);
    
    $attr=$result->fetch_row();
    
    //var_dump($attr);   测试返回的是1是true,0是false
    if($attr[0]==1)
    {
        header("location:main.php");
        }else
        {
            header("location:denglu.php");
            }
            //如果用户名和密码不对,返回的是0,提交给denglu.php,如果都对,返回1,提交给main.php页面
            
原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5315382.html