0

我有这两个函数用于创建用户。第一个函数用于插入/创建用户和其他函数用于检查用户是否/存在于MySql数据库中。但是当我发送数据时,我看到 die() 的空白页;(如果用户存在或用户不存在)如何解决这个错误?以及如何在红色框中打印错误列表,即:

- this user not activate 

- email is empty 

- ....

我的课:

public function createUser($email, $password, $salt, $verification) {

if($this->checkUserFound($email) != true ){die();}

    $query = "INSERT INTO tbUsers (email, password, user_salt, is_verified, is_active, is_admin, verification_code) "
    . "VALUES (?, ?, ?, ?, ?, ?, ?)";

    $stmt = $this->_db->prepare($query);

    $ver = 0;
    $act = 1;
    $adm = 0;

    $stmt->bind_param("sssiiis", $email, $password, $salt, $ver, $act, $adm, $verification);

    if ($stmt->execute()) {
        return true;
    }

    return false;
}

public function checkUserFound($email) {
    $query = "SELECT email FROM tbUsers where email = ?";

    $stmt = $this->_db->prepare($query);

    $stmt->bind_param("s", $email);

    if ($stmt->execute()) {

        $stmt->bind_result($email);

        //fetch first row of results
        $stmt->fetch();
        return false;
    }

    return true;
}
4

2 回答 2

1

这总是会返回FALSE(假设查询成功执行):

if ($stmt->execute()) {

    $stmt->bind_result($email);

    //fetch first row of results
    $stmt->fetch();
    return false;
}

您想将其更改为:

if ($stmt->execute()) {

    $stmt->store_result();


    return 0 == $stmt->num_rows ? FALSE : TRUE;

}

然后,如果找到用户,它将返回TRUE;如果不是 if 将返回FALSE

另外,我认为拥有这个更有意义(语义上):

if($this->checkUserFound($email)){die();}

...因为如果找到用户,您希望它返回TRUE(并结束脚本,因为您不想插入重复项)。/

于 2013-03-31T13:28:54.350 回答
0
if ($stmt->execute()) {

        $stmt->bind_result($email);

        //fetch first row of results
        $stmt->fetch();
        return true;
    }

    return false;
于 2013-03-31T13:28:10.207 回答