PHP编写简单的注册登录页面

登录页面login.html

<meta charset='UTF-8' />
后台管理
<form action="login.php" method='REQUEST'>
用户名 <input type='text' name='username' /><br />
密码 <input type='password' name='password' /><br />
<input type='submit' name='submit' value="登录" />
<a href="register.html">注册a>
form>

PHP编写简单的注册登录页面_第1张图片

登录处理login.php

<meta charset='utf-8'>

@$username = $_REQUEST['username']; #用户名
@$password = $_REQUEST['password']; #密码
$conn = mysqli_connect('localhost','root','root','fuli');
$sql = "select * from admin where username='$username' and password='$password'"; #必须使用双引号,解析变量
$result = mysqli_query($conn,$sql);
$result_array = mysqli_fetch_array($result);
if($result_array['username']==$username and $username!='' and $result_array['password']==$password and $password!=''){
	echo '登录成功';
}
else{
	echo '登录失败';
}
?> 

注册页面register.html

<meta charset='UTF-8' />
后台管理
<form action="register.php" method='REQUEST'>
用户名 <input type='text' name='username' /><br />
密码 <input type='text' name='password1' /><br />
确认密码 <input type='password' name='password2' /><br />
<input type='submit' name='submit' value="注册" />
form>

PHP编写简单的注册登录页面_第2张图片

注册处理register.php

<meta charset='utf-8'>

@$username = $_REQUEST['username']; #用户名
@$password1 = $_REQUEST['password1']; #密码
@$password2 = $_REQUEST['password2']; #密码
$conn = mysqli_connect('localhost','root','root','fuli');
$sql = "select * from admin where username='$username'";
$result = mysqli_query($conn,$sql);
$result_array = mysqli_fetch_array($result);
if($username=='' || $password1=='' || $password2==''){
	echo '请确认信息的完整性!';
}
else{
	if($password1 != $password2){
		echo '密码不一致!';
	}
	else{
		if($result_array){
			echo '用户名已存在!';
		}
		else{
			$sql_insert = "insert into admin value('$username','$password1')";
			$result_insert = mysqli_query($conn,$sql_insert);
			if($result_insert){
				echo '注册成功';
			}
			else{
				echo '系统繁忙,请稍后!';
			}
		}
	}
}
?>

你可能感兴趣的:(PHP,php,数据库,html)