参数号无效:未定义参数

时间:2014-05-07 11:37:41

标签: php

我在验证代码生成方面遇到了一些问题,我仍然是php的新手,这是我尝试修改的代码

我收到了这个错误

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

我的代码如下:

if(!isset($error)){

    //hash the password
    $hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);

    //create the activation code
    function randomActivation() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 4; $i++) {
    $n = rand(0, $alphaLength);
    $pass[] = $alphabet[$n];
}

return implode($pass); //turn the array into a string}



$newactive = randomActivation();  
$activasion = md5(uniqid(rand(),true)); 

    try {

        //insert into database with a prepared statement
        $stmt = $db->prepare('INSERT INTO members (username,password,email,active,ActivationCode) VALUES (:username, :password, :email, :active, :newactive)');
        $stmt->execute(array(
            ':username' => $_POST['username'],
            ':password' => $hashedpassword,
            ':email' => $_POST['email'],
            ':active' => $activasion,
            ':ractive' => $newactive
        ));
        $id = $db->lastInsertId('memberID');

        //send email
        $to = $_POST['email'];
        $subject = "Registration Confirmation";
        $body = "Thank you for registering at demo site.\n\n To activate your account, Please enter the verification Code $newactive\n\n Regards Site Admin \n\n";
        $additionalheaders = "From: <".SITEEMAIL.">\r\n";
        $additionalheaders .= "Reply-To: $".SITEEMAIL."";
        mail($to, $subject, $body, $additionalheaders);

        //redirect to index page
        header('Location: index.php?action=joined');
        exit;

    //else catch the exception and show the error.
    } catch(PDOException $e) {
        $error[] = $e->getMessage();
    }

1 个答案:

答案 0 :(得分:2)

你有

查询中的

:newactive

和绑定

:ractive' => $newactive

所以将其改为

:newactive' => $newactive