数据表里有的账号登录不了,没有的账号说已经注册了 萌新求大佬
登录的php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<?php
$username=$_REQUEST["username"];
$password=$_REQUEST["password"];
$con=mysql_connect("localhost","root","123456") or die("error connecting");
mysql_select_db("user_info",$con);
$dbusername=null;
$dbpassword=null;
$result=mysql_query("select * from user_info where username ='$username';");
while ($row=mysql_fetch_array($result)) {
$dbusername=$row["username"];
$dbpassword=$row["password"];
}
if (is_null($dbusername)) {
?>
<script type="text/javascript">
alert("用户名不存在");
window.location.href="sign-in.html";
</script>
<?php
} else{
if ($dbpassword!=$password){
?>
<script type="text/javascript">
alert("密码错误");
window.location.href="sign-in.html";
</script>
} else {
<script type="text/javascript">
window.location.href="welcome.html";
</script>
<?php
}
}
mysql_close($con);
?>
}
</body>
</html>
注册的php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>注册</title>
</head>
<body>
<?php
session_start();
$username=$_REQUEST["username"];
$password=$_REQUEST["password"];
$con=mysql_connect("localhost","root","123456") or die("error connecting");
mysql_select_db("user_info",$con);
$dbusername=null;
$dbpassword=null;
$result=mysql_query("select * from user_info where username ='{$username}';");
while ($row=mysql_fetch_array($result)) {
$dbusername=$row["username"];
$dbpassword=$row["password"];
}
if(!is_null($dbusername)){
?>
<script type="text/javascript">
alert("用户名已存在");
window.location.href="register.html";
</script>
<?php
}else {
mysql_query("insert into user_info (username,password) values('$username','$password')") or die("存入数据库错误".mysql_error()) ;
mysql_close($con);
?>
<script type="text/javascript">
alert("注册成功");
window.location.href="sign-in.html";
}
}
</script>
</body>
</html>
数据库和表的名称都是user_info