简体   繁体   中英

SQLSTATE[HY093]: error But i dont see why

So here is the code: 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

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. Then you try to execute that completely different statement.

You're creating a statement object stmt2

That gets referenced on the next three lines.

But the next two lines following that reference stmt , not 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 .

Here in first insert query you are passing 5 parameters and binding only 4 parameters.Check this one.i think error might be here.

    $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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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