PHP登入

1.建立登陆页面(登陆和注册差不多)

<body>

<h1>登录页面</h1>

<form action="denglu.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>  隐藏密码

<input type="submit" value="登录" />
</form>

</body>

2.登入页面处理(从一个表中提取数据)

<?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);
$arr = $result->fetch_row();

if($arr[0]==$pwd && !empty($pwd)) 不能为空
{
echo "登录成功";
}
else
{
echo "登录失败";
}

男,女可以用按钮选择。能让用户选择就不手打,能默认,就不显示。

男<input type ="radio" name = "sex" value="1"/>

女<input type ="radio" name = "sex" value="0"/>  name必须相同

a' or 1=1 #   避免这个

posted @ 2017-04-26 16:33  张小琪  阅读(120)  评论(0编辑  收藏  举报