我们可以在prepare语句中查询查询吗?

时间:2018-04-28 14:45:09

标签: php mysqli

我需要在注册表单上检查数据库中的电子邮件激活是真还是假 所以必须做第二次查询。 我想知道我们是否可以在if语句中进行第二次查询?

这里我尝试过,如果不可能的话,我会再次进行第二次查询。 我收到此错误

  

警告:mysqli_stmt :: close():无法在

中获取mysqli_stmt
        $sql = "INSERT INTO users(username, email, password, type, token) VALUES(?, ?, ?, ?, ?)";
        if($stmt = $mysqli->prepare($sql)){
        $stmt->bind_param("sssis", $param_username, $param_email, $param_password, $param_type, $param_token);
    // Set parameters
        $param_username = $username;
        $param_email = $email;
        $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
        $param_type = 0; // Membership type 
        $param_token = $token;
        if($stmt->execute()){
            $stmt = $mysqli->prepare("SELECT emailConfirmation FROM permissons WHERE emailConfirmation = ?");
            $stmt->bind_param("i",$id);
            $stmt->execute();
            $stmt->close();
        if($row['emailConfirmation'] == 1){
                require 'PHPMailer/Exception.php';
                require 'PHPMailer/PHPMailer.php';
                require 'PHPMailer/SMTP.php';   
                $mail = new PHPMailer();
                $mail->setFrom('bilgi@444.com');
                $mail->username = "bilgi@444.com";
                $mail->password = "1444";
                $mail->addAddress($email, $username);
                $mail->Subject = "Please verify email!";
                $mail->isHTML(true);
                $mail->Body = "Thanks for signing up!<br>
                            Please click on the link below:<br><br>

                    <a href='http://xxxxx.com/sitemiz/confirm.php?email=$email&token=$token'>Click Here</a>";

                if ($mail->send()){
                    echo "You have been registered! Please verify your email!";
                }else{
                    echo "Something wrong happened mail! Please try again!";
                }
            } else{
                $user = 'login.php';
                header('Location: '.$user);
                 }
            } else{
                echo "Something went wrong. Please try again later.";
            }
        }

        // Close statement
        $stmt->close();
    }

    // Close connection
    $mysqli->close();
}

请寻求任何帮助或建议。

0 个答案:

没有答案