Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 成员函数错误。有解释怎么解决吗_Php_Oop - Fatal编程技术网

Php 成员函数错误。有解释怎么解决吗

Php 成员函数错误。有解释怎么解决吗,php,oop,Php,Oop,如果用户未登录,我将尝试显示数据,并且出现以下错误: (致命错误:在第58行的/home/a6150953/public_html/php/classes/class.user.php中对非对象调用成员函数Fetch())有帮助吗 class.users.php <?php class User { public $db; public $error; public function __construct($con){ $this-&

如果用户未登录,我将尝试显示数据,并且出现以下错误:

(致命错误:在第58行的/home/a6150953/public_html/php/classes/class.user.php中对非对象调用成员函数Fetch())有帮助吗

class.users.php

<?php
class User
{
    public  $db;
    public  $error;

    public function __construct($con){
            $this->db = $con;
    }

    /*** for login process ***/
    public function check_login($username='', $password=''){
            // Validate that your email is a real one
            if(filter_var($username,FILTER_VALIDATE_EMAIL) !== false) {
                    $password   =   md5($password);
                    $sql        =   "SELECT uid from users WHERE (uemail='$username' or uname='$username') and upass = '$password'";
                    $result     =   $this->db->Fetch($sql);

                        if ($result !== 0) {
                                // this login var will use for the session thing
                                $_SESSION['emailusername']  =   $result[0]['uemail'];
                                $_SESSION['uid']            =   $result[0]['uid'];
                                $_SESSION['user']           =   $this->get_fullname($result[0]['uid'],0);
                                $_SESSION['login']          =   true;
                            }
                        else
                            $this->error['account'] = 'Invalid Username/Password';
                }
            else
                $this->error['email'] = 'Invalid Email Address';

            return  (!isset($_SESSION['emailusername']))? false:true;
        }

    /*** for showing the username or fullname ***/
    public function get_fullname($uid, $write = 1){

            // --> You can prepare, bind, and execute your values here replacing what you have now....<--
            $sql                =   "SELECT * FROM users WHERE uid = $uid";
            $user_data          =   $this->db->Fetch($sql);

            if($user_data !== 0) {
                    $user['fullname']   =   $user_data['fullname'];
                    $user['uemail']     =   $user_data['uemail'];
                    $user['uid']        =   $user_data['uid'];

                    // This gives the option of returning an array (setting session array) or echoing
                    if($write == 1)
                        echo implode("<br />",$user);
                    else
                        return $user;
                }
        }

    public function check_user($uid)
        {
            $sql        =   "SELECT * from users WHERE uid='$uid'";
            $result     =   $this->db->Fetch($sql);
            $count_row  =   ($result !== 0)? count($result): 0;

            return ($count_row == 1);
        }

    /*** starting the session ***/
    public function get_session()
        {
            return $_SESSION['login'];
        }

    public function user_logout()
        {
            $_SESSION['login'] = FALSE;
            session_destroy();
        }
}

您正在构造
用户
,但没有使用方法
获取
(第8行profile.php)的有效数据库连接

我假设(没有看到您的数据库类)


还有一件事吗?如果我想问它:)问一下,如果它不是在你最初的问题下,或者不是一个快速的“为什么这样做?”问题,请考虑我已经决定回退编辑,因为你的编辑使这个问题成为一个全新的问题,答案是无效的。请
<?php
session_start();
//session_destroy();

include_once('php/classes/db_config.php');
include_once('php/classes/class.user.php');

$user1 = new User("");

if(isset($_POST['logout'])) {
        session_destroy();
        header('Location: index.php');
}

include_once('php/common/head.php');

$all    =   $con->Fetch("select * from users");
?>
<div class="wrapper">
<h1>
<?php
if(isset($_SESSION['uid'])){
    echo "Profile Page for  ". $all[0]['fullname'] ." ";
}else{
    echo "Welcome", "<br/><a href='index.php'>Login</a>";
}
?>
</h1>
<pre>
<div id="profile">
<?php
if(isset($_GET['uid']) || isset($_SESSION['uid'])) {

    if($_GET['uid'] === $_SESSION['uid']) {

        echo '<p>'.$all[0]['fullname'].'</p>';
        echo '<p>'.$all[0]['uemail'].'</p>';

        echo "<form action='' method='post'>
            <input type='hidden' name='logout' value='true' />
            <input type='submit' name='submit' value='Logout'>
        </form>";

    }else if($user1->check_user($uid)){

        echo '<p>'.$all[0]['fullname'].'</p>';
        echo '<p>'.$all[0]['uemail'].'</p>';

    }else if(!$user1->check_user($uid)){
        echo "Invalid User";
    }

}else{
    echo "Incorrect";
}
?>
</pre>
</div>
</div>
<?php include_once('php/common/foot.php'); ?>
$user1 = new User("");
$user1 = new User($con);