簡體   English   中英

SQLSTATE [HY093]:錯誤,但我不明白為什么

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

所以這是代碼: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();
    }

是什么原因造成的?

SQLSTATE [HY093]:無效的參數編號:綁定變量的數量與令牌的數量不匹配

我看不到任何基本的遺忘“:”或任何其他真正基本的爛攤子。 你看到什么了嗎

    $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

您將ipaddress參數綁定到一個完全不同的語句。 然后,您嘗試執行該完全不同的語句。

您正在創建一個語句對象stmt2

接下來的三行將對此進行引用。

但是緊隨其后的下兩行引用了stmt ,而不是stmt2

在您的代碼示例中,我們看不到SQL文本或stmt的准備,也沒有看到stmt2的執行。

在第一個插入查詢中,您傳遞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();

將此行替換為您的代碼並進行檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM