本帖最后由 zoenbo 于 2020-11-18 14:52 编辑
尚未入门PHP瞎折腾,大佬们见笑了~ 做一个登录页面,但是怎么也登不了,也不知道问题出哪了,请求大佬们现身赐教~~
[PHP] 纯文本查看 复制代码 <?php
header("Content-Type: text/html; charset=utf8");
$server="localhost";
$db_username="root";
$db_password="root";
$con = mysql_connect($server,$db_username,$db_password);
if(!$con){
die("can't connect".mysql_error());
}
mysql_select_db('test',$con);
if(!isset($_P0ST["submit"])){
exit("错误执行");
}//检测是否有submit操作
include('conn.php');//链接数据库
$name = $_POST['name'];//post获得用户名表单值
$passowrd = $_POST['password'];//post获得用户密码单值
if ($name && $passowrd){//如果用户名和密码都不为空
$sql = "select * from user where username = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
$result = mysql_query($sql);//执行sql
$rows=mysql_num_rows($result);//返回一个数值
if($rows){//0 false 1 true
header("refresh:0;url=index.php");//如果成功跳转至index.php页面
exit;
}else{
echo "用户名或密码错误";
echo "
<script>
setTimeout(function(){window.location.href='login.php';},1000);
</script>
";//如果错误使用js 1秒后跳转到登录页面重试;
}
}else{//如果用户名或密码有空
echo "表单填写不完整";
echo "
<script>
setTimeout(function(){window.location.href='login.php';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试;
}
mysql_close();//关闭数据库
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆</title>
</head>
<body>
<form name="login" action="login.php" method="post">
<p>用户名<input type=text name="name"></p>
<p>密 码<input type=password name="password"></p>
<p><input type="submit" name="submit" value="登录"></p>
</form>
</body>
</html> |