日期:2014-05-17 浏览次数:20505 次
login.html <html> <head> <title>用户系统登录</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <form name="loginfrom" action="userController.php?flag=login"method="POST"> <table background="resource/background.jpg" width= "100%" height= "100%" border= "0 "> <tr> <td align= "center " valign= "middle "> <table align="center"> <tr> <th>角色</th> <td><input type="radio" name="account" value="admin" checked>管理员 <input type="radio" name="account" value="teacher">教师 <input type="radio" name="account" value="student">学生 </td> <tr> <th>用户名</th> <td><input type="text" name="user_name" ></td> </tr> <tr> <th>密码</th> <td><input type="password" name="user_password" ></td> </tr> <tr> <td align="right" colspan="2"><a href="register.html">新用户注册</a><button type="submit" name="submit">登录</button></td> </tr> </table> </td> </tr> </table> </form> </body> </html>
dbconn.class.php <?php class DBconn{ private static $db_host="localhost"; private static $db_user="root"; private static $db_password="linux"; private static $db_name="sharewebDb"; private static $connection; static function getConn(){ $connection=new mysqli($db_host,$db_user,password,$db_name); return $connection; } } ?>
userModel.php <?php include("dbconn.class,php"); class userModel{ function checklogin($userid,$userpwd,$useraccount){ $mysqli=DBconn::getConn(); $result=''; switch($useraccount){ case "teacher":{ $sql="select t_id,t_name,t_dep from ter_info where t_id=? and t_pwd=?"; $result=$mysqli->prepare($sql);: $result->bind_param("ss",$user_id,$user_password); $user_id=$userid; $user_password=$userpwd; $result->execute();break; } case "student":{ $sql="select s_id,s_name,s_dep from stu_info where s_id=? ands_pwd=?"; $result=$mysqli->prepare($sql); $result->bind_param("ss",$user_id,$user_password); $user_id=$userid; $user_password=$userpwd; $result->execute();break; } } $result->bind_result($user_id,$user_name,$user_dep); while($result->fetch()){ $userlist=array( 'user_id'=>$user_i