存在的表列的未定义索引

时间:2017-07-17 22:24:25

标签: php sql pdo

我正在开展一个大学项目,该项目涉及建立一个可以访问数据库以运行查询的网站。该网站有一个登录系统,直到今晚,才能从名为“客户”的表中检索登录详细信息。 现在我遇到了一个奇怪的问题,PHP给出了以下错误:

  

PHP注意:未定义的索引:第88行的D:\ Work \ CEUR16-004 \ Project \ www_root \ includes \ scripts \ php \ libCust \ login_out.php中的customer_id

表'客户'存在,' customer_id'字段也存在,在SQL Server Management Studio中检查它。如果我尝试拨打“客户”中的任何其他字段,我会遇到同样的问题。表,但在网站的其他部分调用的其他表工作绝对正常。我已经尝试了var_dump并且没有返回任何内容,这没有任何意义,因为没有对此类进行任何更改会导致它突然中断。

以下是该类的代码:

<?php
// libCust/login_out.php
// This file contains the login/logout class(es) and functions required for the newsagents customers. Class(es) and functions related to the login/logout of admin accounts are located in libAdmin/login_out.php

class login_out
{
    // This class contains the functions required for customers to manage their account

    // Public Vars
    public $email;
    public $login_err;
    public static $user_id;
    // Protected Vars
    protected $dbcore_login_out;
    protected $session_id;
    // Private Vars
    private $password;
    private $err_handle;

    public function __construct($err_handle)
    {
        $this->err_handle = $err_handle;
        $this->dbcore_login_out = DBCore::DBInstance();
    }

    public function get_email()
    {
        return $this->email;
    }

    public function set_email($email_set)
    {
        $this->email = $email_set;
    }

    public function login_check($email_post, $password_post)
    {
        $this->email = trim($email_post);
        $this->password = trim($password_post);
        if($this->email == "" || $this->password == "")
        {
            $this->login_err = $this->err_handle->generate_error("login_form_empty_param", "user", "null");
            unset($this->email);
            unset($this->password);
            $_SESSION['login_err'] = $this->login_err;
            return 1;
        }
        elseif(filter_var($this->email, FILTER_VALIDATE_EMAIL) == "FALSE")
        {
            $this->login_err = $this->err_handle->generate_error("login_form_invalid_email", "user", "null");
            unset($this->email);
            unset($this->password);
            $_SESSION['login_err'] = $this->login_err;
            return 1;
        }
        else
        {
            try
            {
                $query = 'SELECT customer_password FROM customers WHERE customer_email = :customer_email';
                $stmt = $this->dbcore_login_out->dbc->prepare($query);
                $stmt->bindParam(':customer_email', $this->email);
                $stmt->execute();
                $user_fetch = $stmt->fetch();
                if(!($user_fetch))
                {
                    $this->login_err = $this->err_handle->generate_error("login_form_details_incorrect", "user", "null");
                    unset($this->email);
                    unset($this->password);
                    $_SESSION['login_err'] = $this->login_err;
                    return 1;
                }
                else
                {
                    if($user_fetch['customer_password'] !== $this->password)
                    {
                        $this->login_err = $this->err_handle->generate_error("login_form_details_incorrect", "user", "null");
                        unset($this->email);
                        unset($this->password);
                        $_SESSION['login_err'] = $this->login_err;
                        return 1;
                    }
                    else
                    {
                        session_destroy();
                        unset($this->password);
                        unset($_SESSION['login_err']);
                        self::$user_id = $user_fetch['customer_id'];
                        $session_prefix = preg_replace('/[^A-Za-z0-9]/', '', $this->email);
                        $this->session_id = session_create_id($session_prefix . "-");
                        session_id($this->session_id);
                        session_start();
                        $_SESSION['user_logged_in'] = "user_logged_in";
                        $_SESSION['customer_id'] = self::$user_id;
                    }
                }
            }
            catch(PDOException $e)
            {
                exit($this->err_handle->generate_error("login_db_error", "db", $e));
            }
        }
        return "success";
    }

    public function logout()
    {
        if(!(session_id()))
        {
            return "user_not_logged_in";
        }
        else
        {
            unset($this->email);
            unset($this->session_id);
            session_destroy();
            session_start();
            $_SESSION['user_logged_in'] = "";
        }
        return "user_logged_out";
    }
}
?>

非常感谢任何帮助。

0 个答案:

没有答案