php与数据库相关重要有关问题求解答

php中文网
发布: 2016-06-13 13:30:44
原创
1082人浏览过

php与数据库相关重要问题求解答
各位前辈高人,我在login.html中点击登录后直接转向userController.php,并且不显示任何东西,我的目的是验证登录成功后直接跳到mian.html 不成功则跳到error.html中,可是不成功,请问我哪里错了,还有一个问题就是登录成功后怎么吧登录者的信息传给mian.html?谢谢了


PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> 
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>

登录后复制

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
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;
        }    
    }
?>

登录后复制

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
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-&gt;bind_param("ss",$user_id,$user_password);
                $user_id=$userid;
                $user_password=$userpwd;
                $result-&gt;execute();break;
                }
        case "student":{
                $sql="select s_id,s_name,s_dep from stu_info where s_id=? ands_pwd=?";
                $result=$mysqli-&gt;prepare($sql);
                $result-&gt;bind_param("ss",$user_id,$user_password);
                $user_id=$userid;
                $user_password=$userpwd;
                $result-&gt;execute();break;
                }
        }
        $result-&gt;bind_result($user_id,$user_name,$user_dep);
        while($result-&gt;fetch()){
            $userlist=array(
                'user_id'=&gt;$user_id,
                'user_name'=&gt;$user_name,
                'user_dep'=&gt;$user_dep
            );        
        }
        $result-&gt;close();
        $mysqli-&gt;close();
        return userlist;
    }
?&gt;

 <div class="clear"></div>
登录后复制
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号