<?php
$servername
=
"服务器名"
;
$username
=
"账户名"
;
$password
=
"密码"
;
$dbname
=
"数据库名"
;
?>
<?php
session_start();
if
(isset(
$_POST
['uname']) && isset(
$_POST
['pwd'])){
$name
=
$_POST
['uname'];
$pwd
=
$_POST
['pwd'];
$conn
=
new
mysqli(
$servername
,
$username
,
$password
,
$dbname
);
if
(
$conn
->connect_error) {
die
(
"Connection failed: "
.
$conn
->connect_error);
}
$sql
=
"SELECT * FROM test_students_all WHERE (student_name='$name') AND (password='$pwd')"
;
$result
=
$conn
->query(
$sql
);
if
(
$result
->num_rows > 0) {
$_SESSION
['user_account'] =
$name
;
while
(
$row
=
$result
->fetch_assoc()) {
echo
'<p>' .
$row
['student_nbr'] . '<br/>' .
$row
['student_name'] . '(' .
$row
['sex'] . ')' . '<br/>' .
$row
['
class
'] . '<br/>' .
$row
['major'].'</p>';
echo
'<p><img src=
"student_images/' . $row['class'] . '/' . $row['student_nbr'] . '.jpg"
/></p>';
}
}
else
{
echo
"没有您要的信息"
;
}
$conn
->close();
}
?>
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<title>登录校验</title>
</head>
<body>
<p>
<?php
if
(isset(
$_SESSION
['user_account'])){
echo
'你好,' .
$_SESSION
['user_account'];
}
else
{
echo
'游客';
}
?>
</p>
<form method=
"POST"
>
<input type=
"text"
name=
"uname"
placeholder=
"用户名"
/>
<br />
<input type=
"password"
name=
"pwd"
placeholder=
"密码"
/>
<br />
<input type=
"submit"
>
</form>
</body>
</html>