<?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
(
"错误执行"
);
}
include
(
'conn.php'
);
$name
=
$_POST
[
'name'
];
$passowrd
=
$_POST
[
'password'
];
if
(
$name
&&
$passowrd
){
$sql
=
"select * from user where username = '$name' and password='$passowrd'"
;
$result
= mysql_query(
$sql
);
$rows
=mysql_num_rows(
$result
);
if
(
$rows
){
header(
"refresh:0;url=index.php"
);
exit
;
}
else
{
echo
"用户名或密码错误"
;
echo
"
<script>
setTimeout(
function
(){window.location.href=
'login.php'
;},1000);
</script>
";
}
}
else
{
echo
"表单填写不完整"
;
echo
"
<script>
setTimeout(
function
(){window.location.href=
'login.php'
;},1000);
</script>";
}
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>