php登录注册页面

一、注册页面

1、首先要用form表单做一个注册页面:

<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="text" name="name" /></div>
<div>性别:
男<input type="radio" name="sex" value="1"/><input type="radio" name="sex" value="0"/></div>
<div>生日:<input type="text" name="birthday" /></div>
<div><input type="submit" value="注册" /></div>

</form>

2、做一个纯php的页面来获取注册页面的数据

<?php
//1.取提交的数据
$uid=$_POST["uid"];//如果是get,就用$_GET()
$pwd=$_POST["pwd"];
$name=$_POST["name"];
$sex=$_POST["sex"];
$birthday=$_POST["birthday"];
//2.向数据库写入
$db=new MySQLi("localhost","root","123","text_0306");
$sql="insert into users
values('{$uid}','{$pwd}','{$name}',{$sex},'{$birthday}')";//这里取每个列名
if($db->query($sql))
{
    echo"注册成功";
}
else
{
    echo"注册失败";    
}


?>

二、登陆页面

1、做一个登陆页面的form表单:

<body>
<h1>登陆页面</h1>
<form action="denglu1.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>

2、做一个纯php页面来获取登陆页面的数据

<?php
//1.取提交的数据
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
//2.向数据库写入
$db=new MySQLi("localhost","root","123","text_0306");
$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"登录失败";    
}

?>

 

posted @ 2017-04-26 15:54  梦深深处  阅读(1436)  评论(1编辑  收藏  举报