<html>
<body>
<?php
header("Content-Type:text/html;charset=gb2312");
//isset检测变量是否被设置,最好使用上,可以不使用他的。
//学生登录
if(isset($_POST["login_student"]) && $_POST["login_student"] =="student"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('Please input username or password.'); history.go(-1);</script>"; //弹出提示框返回上一
}
else{
$con=mysql_connect("localhost","root","yuanhui");
mysql_select_db("School",$con);
mysql_query("set names 'gb2312'");
$result=mysql_query("select Password from Student where Username ='$user' ");//mysql_query 查询数据库的函数
if($row=mysql_fetch_array($result)){
if($row[0]==""){
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[0]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
echo "Login Sucessfully";
}
}
}
}
//教师登录
if(isset($_POST["login_teacher"]) && $_POST["login_teacher"] =="teacher"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('Please input username or password.'); history.go(-1);</script>"; //弹出提示框返回上一
}
else{
$con=mysql_connect("localhost","root","yuanhui");
mysql_select_db("School",$con);
mysql_query("set names 'gb2312'");
$result=mysql_query("select Password from Teacher where Username ='$user' ");//mysql_query 查询数据库的函数
if($row=mysql_fetch_array($result)){
if($row[0]==""){
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[0]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
echo "Login Sucessfully";
}
}
}
}
mysql_close($con);//结束之后,关闭数据库。
?>
</body>
</html>
<body>
<?php
header("Content-Type:text/html;charset=gb2312");
//isset检测变量是否被设置,最好使用上,可以不使用他的。
//学生登录
if(isset($_POST["login_student"]) && $_POST["login_student"] =="student"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('Please input username or password.'); history.go(-1);</script>"; //弹出提示框返回上一
}
else{
$con=mysql_connect("localhost","root","yuanhui");
mysql_select_db("School",$con);
mysql_query("set names 'gb2312'");
$result=mysql_query("select Password from Student where Username ='$user' ");//mysql_query 查询数据库的函数
if($row=mysql_fetch_array($result)){
if($row[0]==""){
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[0]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
echo "Login Sucessfully";
}
}
}
}
//教师登录
if(isset($_POST["login_teacher"]) && $_POST["login_teacher"] =="teacher"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('Please input username or password.'); history.go(-1);</script>"; //弹出提示框返回上一
}
else{
$con=mysql_connect("localhost","root","yuanhui");
mysql_select_db("School",$con);
mysql_query("set names 'gb2312'");
$result=mysql_query("select Password from Teacher where Username ='$user' ");//mysql_query 查询数据库的函数
if($row=mysql_fetch_array($result)){
if($row[0]==""){
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[0]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
echo "Login Sucessfully";
}
}
}
}
mysql_close($con);//结束之后,关闭数据库。
?>
</body>
</html>