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); //將數(shù)據(jù)以索引方式儲存在數(shù)組中 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"){ //醫(yī)生的頁面 echo"<script>alert('登錄成功哦,您是醫(yī)生!');location.href='../hospitalmain.html'</script>"; } else{ //管理員的頁面 echo"<script>alert('登錄成功哦,您是管理員!');location.href='../adminmain.html'</script>"; } /*echo "<script>alert('登錄成功!歡迎回來!');window.location.href='../costmain.html'</script>";*/ } ?>
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.