简体   繁体   中英

Fatal error: Call to a member function check_login() on a non-object

I have the following login form :

<?php
include 'database/db_connect.php';

$link = mysqli_connect($host_name, $user_name, $password, $database);
// check connection
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?><?php
session_start();
include 'database/websrvc.php';

$user = new Websrvc();

if (isset($_REQUEST['submit'])) {
    extract($_REQUEST);
    $login = $websrvc->check_login($emailusername, $password);
    if ($login) {
        // Registration Success
        header("location:main.php");
    } else {
        // Registration Failed
        echo 'Wrong username/email or password';
    }
}
?>
 <form action="" method="post" name="login">
                <table class="table " width="400">
                    <tr>
                        <th> <label class="fieldstyle_with_label"> UserName or Email:   </label> </th>
                        <td><input type="text" name="emailusername" required></td>
                    </tr>
                    <tr>
                        <th><label class="fieldstyle_with_label"> Password : </label></th>
                        <td><input type="password" name="password" required></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input class="large_button" type="submit" name="submit" value="Login" onclick="return(submitlogin());"></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>

                    </tr>

                </table>
            </form>

When I try to log in using the folowing script, I get the following Fatal Error : Fatal error: Call to a member function check_login() on a non-object in /homepages/23/d81301375/htdocs/emarps/login

Below is my class web_srvc.php that is supposed that handles the check_login :

 public function check_login($emailusername, $password) {
        $link = $this->db_connection();
        $password = md5($password);

        //checking if the username is available in the table
        $result = mysqli_query($link, "SELECT user_id,user_name,role_id,status from users WHERE email='$emailusername' or user_name='$emailusername' and password='$password'");
        $user_data = mysqli_fetch_array($result, MYSQLI_BOTH);
        $count_row = mysqli_num_rows($result);

        if ($count_row == 1) {
            $_SESSION['login'] = true; // this login var will use for the session thing
            $_SESSION['uid'] = $user_data['uid'];
            return true;
        } else {
            return false;
        }
    } 
$login = $websrvc->check_login($emailusername, $password);

改成

$login = $user->check_login($emailusername, $password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM