0

我在使用 WAMP(php 5.3.13 和 mysql 5.5.24)的 php 中有问题。我的问题是当我测试注册表时:

include "config.php";
if(isset($_GET['confirm_registration'])){
    User::ConfirmRegistration($_GET['confirm_registration']);
}
if(isset($_POST['confirm_registration'])){
    $username= $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];
    if(!Validator::Email($email)){
        echo "Invalid email address";
    } else {
        User::BeginRegistration($username,$email,$password);
    }
}
?>

<div id="contentWrapper">
<div id="form">
<form id="signup" method="POST" action="">
    <div class="signup_form"><strong>Sign up</strong></div>
    <div class="signup_form">
        <label>Username</label>
        <input type="text" id="username" name="username" size="30">
    </div>
    <div class="signup_form">
        <label>E-Mail</label>
        <input type='text' id='email' name='email' size="30">
    </div>
    <div class="signup_form">
        <label>Password</label>
        <input type='password' id='password' name='password' size="30">
    </div>
    <div class="signup_form">
        <label></label>
        <input type='submit' name="confirm_registration" value='Submit'>
    </div>
</form>
</div>
</html>

这是错误:Call to a member function query()on a non-object in C:\wamp\www\zavrsni_rad\classes\DataBase.class.php 第 11 行

这是数据库类:

class DataBase
{
    public static $connection;
    public static function Connect(){
        self::$connection = new mysqli("localhost","root","","zavrsni_rad");
        self::$connection->set_charset("utf8"); 
    }
    public static function Execute($query){ 
        self::$connection->query($query);
    }
    public static function GetString($query){
        $r = self::$connection->query($query);
        $res_arr = $r->fetch_row();
        return $res_arr[0];
    }
    public static function GetRow($query){
        $r = self::$connection->query($query);
        return $r->fetch_row();
    }
    public static function GetTable($query){
        $r = self::$connection->query($query); 
        $res = array();

        while($rw = $r->fetch_row()){
            $res[] = $rw;
        }
        return $res;
    }
    public static function Disconnect(){
        self::$connection->close();
    }
}
4

1 回答 1

0

当您调用时,显然self::$connection尚未实例化Execute()- 您应该在Connect()之前运行。

于 2013-06-30T12:21:13.550 回答