如何使用mysql在其他页面发送人 [英] How to send people at different page with mysql

查看:94
本文介绍了如何使用mysql在其他页面发送人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录页面,并且有2种帐户.我添加了一列,以确切地知道它们是"agent"还是"notagent".我想做的是,当连接代理"帐户时,他将转到account1.php,而不是"notagent"帐户将转到account2.php.我该如何实现?到目前为止,这就是我的代码.

I have a login page and there is 2 kind of account. I added a column to know exactly if they are "agent" or "notagent". What I want to do is when a "agent" account is connected, he will go to account1.php, instead of "notagent" account will go to account2.php . How can I achieve that? This is what my code looks like so far...

<?php 

include_once('connectiondb.php');

class User {

    private $db;

    public function __construct() {
        $this->db = new Connection();
        $this->db = $this->db->dbConnect();
    }

    public function Login($name, $pass){
        if(!empty($name) && !empty($pass)) {
            $st = $this->db->prepare("select * from users where username=? and password=?");
            $st->bindParam(1,$name);
            $st->bindParam(2,$pass);
            $st->execute();

            if($st->rowCount() == 1) {
                header("Location: compte.php");
                die();
            } else {
                echo 'Incorrect username or password.';
            }
        } else {
            echo 'Please enter username and password';
        }
    }

我认为应该用另一个if语句代替header(...),但是应该在其中写什么?如何验证他是代理商帐户还是非代理商帐户?

I think that instead of header(...) I should put another if statement, but what should I write inside of it? How can I verify if he is a agent or notagent account?

推荐答案

您可以获取结果,然后在rowCount() check

You can fetch the results and do another if statement inside your rowCount() check

public function Login($name, $pass){
    if(!empty($name) && !empty($pass)) {
        $st = $this->db->prepare("select * from users where username=? and password=?");
        $st->bindParam(1,$name);
        $st->bindParam(2,$pass);
        $st->execute();
        $results = $st->fetchObject();

        if($st->rowCount() == 1) {
            if ($results->colName == "agent") { // Change colName to any column that contains the agent and notagent value
                header("Location: account1.php");
            } else {
                header("Location: account2.php");
            }
        } else {
            echo 'Incorrect username or password.';
        }
    } else {
        echo 'Please enter username and password';
    }
}

这篇关于如何使用mysql在其他页面发送人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆