简体   繁体   English

SQLSTATE [HY093]:错误,但我不明白为什么

[英]SQLSTATE[HY093]: error But i dont see why

So here is the code: try{ 所以这是代码:try {

        $db->beginTransaction();
        $ipaddress = getenv('REMOTE_ADDR');
        $stmt2 = $db->prepare("INSERT INTO members (username, email, password, signup_date, ipaddress) VALUES (:username, :email1, :bcrypt, now(), :ipaddress)");
        $stmt2->bindParam(':username', $username, PDO::PARAM_STR);
        $stmt2->bindParam(':email1', $email1, PDO::PARAM_STR);
        $stmt2->bindParam(':bcrypt',$bcrypt, PDO::PARAM_STR);
        $stmt->bindParam(':ipaddress', $ipaddress, PDO::PARAM_INT);
        $stmt->execute();
        //get the last id inserted to the db which is now this users id for activation and member folder creation///
        $lastId = $db->lastInsertId();
        $stmt3 = $db->prepare("INSERT INTO activate (user, token) VALUES (:lastId , :token)");
        $stmt3->bindValue(':lastId', $lastId, PDO::PARAM_STR);
        $stmt3->bindValue(':token', $token, PDO::PARAM_STR);
        $stmt3->execute();
        //send email activation to new user///
        $from = "From: Auto Responder @ geekifyme <admin@geekifyme.org>";
        $subject = "IMPORTANT: Activate your geekifyme account";
        $link = "http://www.geekifyme.org/scripts/activate.php?user='.$lastId.'$token='.$token.";
        //strt email body////
        $message = "
        Thanks for registering an account at GeekifyMe!  There is just one last step in setting up your account.  Please click the link below to confirm your identity and get started.  If the link below is not active please copy and paste it into your browser bar.

        $link
        ";
        //set headers////
        $headers = 'MIME-Version: 1.0' . "rn";
        $headers .= "Content_type: textrn";
        $headers .=  "From: $fromrn";
        //send the email now/////
        mail($email1, $subject, $message, $headers);
        $db->commit();
        echo 'Thanks for joining! Check your email in a few moments to activate your account so that you may log in.';
        $db = null;
        exit();
    }
    catch(PDOException $e){
        $db->rollBack();
        echo $e->getMessage();;
        $db = null;
        exit();
    }

What could cause this? 是什么原因造成的?

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配

I don't see any of the basic forgetting a ':' or any other really basic mess ups. 我看不到任何基本的遗忘“:”或任何其他真正基本的烂摊子。 Can you see anything? 你看到什么了吗

    $stmt2 = $db->prepare("INSERT INTO members (username, email, password, signup_date, ipaddress) VALUES (:username, :email1, :bcrypt, now(), :ipaddress)");
         ^---- note the 2
    $stmt->bindParam(':ipaddress', $ipaddress, PDO::PARAM_INT);
         ^--- note the LACK of a 2
    $stmt->execute();
         ^--- ditto

You're binding your ipaddress param to a completely different statement. 您将ipaddress参数绑定到一个完全不同的语句。 Then you try to execute that completely different statement. 然后,您尝试执行该完全不同的语句。

You're creating a statement object stmt2 您正在创建一个语句对象stmt2

That gets referenced on the next three lines. 接下来的三行将对此进行引用。

But the next two lines following that reference stmt , not stmt2 . 但是紧随其后的下两行引用了stmt ,而不是stmt2

We don't see the SQL text or the prepare for stmt in your code example, and we don't see an execute for stmt2 . 在您的代码示例中,我们看不到SQL文本或stmt的准备,也没有看到stmt2的执行。

Here in first insert query you are passing 5 parameters and binding only 4 parameters.Check this one.i think error might be here. 在第一个插入查询中,您传递5个参数并仅绑定4个参数。检查此参数。我认为可能是错误的。

    $stmt2 = $db->prepare("INSERT INTO members (username, email, password, signup_date, ipaddress) VALUES (:username, :email1, :bcrypt, now(), :ipaddress)");
    $stmt2->bindParam(':username', $username, PDO::PARAM_STR);
    $stmt2->bindParam(':email1', $email1, PDO::PARAM_STR);
    $stmt2->bindParam(':bcrypt',$bcrypt, PDO::PARAM_STR);
    $stmt2->bindParam(':ipaddress', $ipaddress, PDO::PARAM_INT);
    $stmt2->execute();

Replace this line with your code and check it. 将此行替换为您的代码并进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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