Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无效的参数编号:未定义参数_Php - Fatal编程技术网

Php 无效的参数编号:未定义参数

Php 无效的参数编号:未定义参数,php,Php,我在生成验证代码时遇到了一些问题,我对php还是新手,这就是我试图修改的代码 我犯了这个错误 SQLSTATE[HY093]: Invalid parameter number: parameter was not defined 我的代码如下: if(!isset($error)){ //hash the password $hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYP

我在生成验证代码时遇到了一些问题,我对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();
    }
if(!isset($error)){
//散列密码
$hashedpassword=$user->password\u散列($\u POST['password'],password\u BCRYPT);
//创建激活码
函数随机激活(){
$alphabet=“abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyzo123456789”;
$pass=array();//记住将$pass声明为数组
$alphaLength=strlen($alphabet)-1;//将长度-1放入缓存
对于($i=0;$i<4;$i++){
$n=兰特(0,$alphaLength);
$pass[]=$alphabet[$n];
}
return introde($pass);//将数组转换为字符串}
$newactive=randomActivation();
$activasion=md5(uniqid(rand(),true));
试一试{
//使用准备好的语句插入数据库
$stmt=$db->prepare('INSERT-INTO-members(username、password、email、active、ActivationCode)值(:username、:password、:email、:active、:newactive)');
$stmt->execute(数组)(
':username'=>$\u POST['username'],
':password'=>$hashedpassword,
“:email'=>$\u POST['email'],
“:活动”=>$activasion,
':ractive'=>$newactive
));
$id=$db->lastInsertId('memberID');
//发送电子邮件
$to=$_POST['email'];
$subject=“注册确认”;
$body=“感谢您在演示站点注册。\n\n要激活您的帐户,请输入验证码$newactive\n\n作为站点管理员\n\n”;
$additionalheaders=“From:\r\n”;
$additionalheaders.=“回复:$”.SITEEMAIL.“;
邮件($to、$subject、$body、$additionalheaders);
//重定向到索引页
标题('Location:index.php?action=joined');
出口
//否则捕获异常并显示错误。
}捕获(PDO$e){
$error[]=$e->getMessage();
}
您有

:查询中的newactive

和约束

:ractive' => $newactive
所以把它改成

:newactive' => $newactive

:newactive和:ractive是不同的词。