duanbing2963 2014-05-07 11:37
浏览 74
已采纳

参数号无效:参数未定义[关闭]

i was having some issues with the verification code generation, i am still new to php and this is the code i try to modify

and i got this error

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

my code below:

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.

 To activate your account, Please enter the verification Code $newactive

 Regards Site Admin 

";
        $additionalheaders = "From: <".SITEEMAIL.">
";
        $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条回答 默认 最新

  • donglei1616 2014-05-07 11:39
    关注

    You have

    :newactive in the query

    and binding

    :ractive' => $newactive
    

    So change it to

    :newactive' => $newactive
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。