As a novice, I originally imagined that when adding a user, I would select the value of value, enter the username and password when logging in, and at the same time determine whether the value of the selected value is 0 or 1, and enter different pages
The value is saved in the database as class
But I don’t know how to take a certain person’s class value out of the database. Judgment, I don’t know how to improve the code. Please give me some advice.
<meta charset="utf-8"> <?php if(isset($_POST["submit"]) && $_POST["submit"] == "登陆") { $user = $_POST["username"]; $psw = $_POST["password"]; $Dclass = $_POST["class"]; if($user == "" || $psw == "") { echo "<script>alert('请输入用户名或密码!'); history.go(-1);</script>"; } else { mysql_connect("localhost","root","root"); mysql_select_db("hospital"); mysql_query("set names utf-8"); $sql = "select username,password,ID,class from user where username = '$_POST[username]'and password = '$_POST[password]'"; $result = mysql_query($sql); $num = mysql_num_rows($result); if($num) { $row = mysql_fetch_array($result); //将数据以索引方式储存在数组中 echo $row[0]; } else { echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>"; } } } else { mysql_connect("localhost","root","root"); mysql_select_db("hospital"); mysql_query("set names utf-8"); $sql = " Dclass = '$_POST[class]'"; $result = mysql_query($sql); if($result=="0"){ //医生的页面 echo"<script>alert('登录成功哦,您是医生!');location.href='../hospitalmain.html'</script>"; } else{ //管理员的页面 echo"<script>alert('登录成功哦,您是管理员!');location.href='../adminmain.html'</script>"; } /*echo "<script>alert('登录成功!欢迎回来!');window.location.href='../costmain.html'</script>";*/ } ?>
灵魂独行2018-06-17 21:58:29
It is recommended to use ajax to verify the data. You can obtain the data in the class through js and make logical judgments before jumping.