实例一登录
登录
登录窗口页面
<!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="dlchuli.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>密码:<input type="text" name="pwd" /></div> <input type="submit" value="登录" /> </form> </body> </html>
登录处理验证
<?php $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; //造对象 $db = new MySQLi("localhost","root","123","mydb"); //判断是否出错 !mysqli_connect_error() or die("连接失败!"); //写SQL语句 //容易被SQL注入攻击,不安全 //$sql = "select count(*) from Users where Uid = '{$uid}' and Pwd='{$pwd}'"; $sql = "select Pwd from Users where Uid='{$uid}'"; //执行SQL语句 $result = $db->query($sql); //取数据 $attr = $result->fetch_row(); if($attr[0] == $pwd) { header("location:main.php"); } else { echo "登录失败!"; }