php实现注册和登录验证
html:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <form action="zhuce.php" method="post"> 账号:<input name="uid"/><br /> 密码:<input name="pwd"/><br /> <input type="submit"/> </form> </body> </html>
post方式传值
注册:
<meta charset="utf-8"> <?php /*连接数据库*/ $db = new MySQLi('localhost','root','','z_1031'); !mysqli_connect_error() or die('数据库连接失败'); $db->query('set names utf8'); //接收用户输入 $uid = $_POST['uid']; $pwd = $_POST['pwd']; $name = $uid; $sql = "insert into user(id,pwd,name) values('$uid','$pwd','$name')"; $res = $db->query($sql); //添加 var_dump($res);
获取用户的账号和密码,写SQL语句,返回结果集,将结果集转化为一维数组,当pwd不为零且正确时输出登陆成功。
注意:这两个不是同一个PHP文件!!!!!