0

连接.php

<?php
$host = "localhost";
$user = "root";
$pass = "mikred###";
$db = "itsupportdb";

$mysqli = new mysqli($host, $user, $pass, $db);
if(mysqli_connect_errno())
{
    printf("Connection Failed: %s\n", mysqli_connect_error());
    exit();
}
?>

glbLoginFunct.php

<?php
        include("connection.php");  
        class Functions {

            public static function __Login()
            {           
                session_start();

                if(isset($_POST['btnLogin']))
                {           
                    $id = $_POST['user'];
                    $pass = $_POST['pass'];

                    $query = $mysqli->prepare("SELECT * FROM syslogin WHERE username=? AND password=? LIMIT 1");
                    $query->bind_param('ss', $id, $pass);
                    $query->execute();
                    $query->bind_result($id, $pass);
                    $row = $query->fetch();
                    if($row == true) 
                    {
                        $_SESSION['LogID'] = 1;
                        $_SESSION['ProfID'] = 2;
                        header('Location: test.php');
                        exit();
                    }
                    else 
                    {
                        ?><script type="text/javascript"> alert('ERROR!'); </script><?php
                    }
                }
            }

        }
    ?>

mainLogin.php

<?php require("includes/glbLoginFunct.php"); ?>
<form action="<?php $_PHP_SELF ?>" method="POST">
<fieldset>
    <legend>LOGIN FORM:</legend>
    <label id="user">Username: <input type="text" name="user" maxlenght="10"/></label><br />
    <label id="pass">Password: <input type="password" name="pass" maxlenght="7"/></label><br />
    <label id="buttons"><input type="submit" class="imgBtn" name="btnLogin" value="Login User"/></label><br />              
    <a href="index.php?link=Forgot">Forgot Password</a>
</fieldset>
</form>
<?php Functions::__Login() ?>

为什么说:

注意:未定义变量:mysqli in ...\includes\glbLoginFunct.php 第 14 行

致命错误:在第 14 行的 ...\includes\glbLoginFunct.php 中调用非对象的成员函数 prepare()

4

1 回答 1

0

要么制作$mysqli函数的参数,要么输入:

global $mysqli;

__Login函数的开头。

顺便说一句,您不应该为您的函数使用该名称。从魔术方法的文档中:

注意:PHP 保留所有以 __ 开头的函数名作为魔法。建议您不要在 PHP 中使用带有 __ 的函数名,除非您想要一些记录在案的魔术功能。

于 2013-11-11T03:22:38.580 回答