Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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 SQLSTATE[HY093]:参数编号无效:未在OOP中定义参数_Php - Fatal编程技术网

Php SQLSTATE[HY093]:参数编号无效:未在OOP中定义参数

Php SQLSTATE[HY093]:参数编号无效:未在OOP中定义参数,php,Php,我有这个功能: private function sendVerification($username, $email) { global $pdo; $this->check = $pdo->prepare("SELECT * FROM users where user_name = :username AND user_email = :email"); $this->check->execute(ar

我有这个功能:

    private function sendVerification($username, $email)
    {
        global $pdo;

        $this->check = $pdo->prepare("SELECT * FROM users where user_name = :username AND user_email = :email");
        $this->check->execute(array(
        ":username" => $username,
        ":email" => $email
        ));

        if ($this->check->rowCount())
        {
            $this->get = $this->check->fetch(PDO::FETCH_ASSOC);

            $this->insert = $pdo->prepare
            ("
            INSERT INTO account_verification 
            (user_id, generated_code, date, time) 
            VALUES
            (:id, :code, CUTDATE(), CURTIME())
            ");

            $this->insert->execute(array(
            ":id" => $this->get['user_id'],
            "generated_code" => Users::generateCode($email)
            ));
        }
        else
        {
            throw new exception ("An error has occured!");
        }
    }
访问此静态

    public static function generateCode($salt)
    {
        return substr(hash('sha512', $salt), 0, 15);
    }
首先,我使用用户名和电子邮件来验证是否与他们有冲突, 然后我添加了一个var,它将保存一个获取的数组

然后我检查它的行数,然后插入数据

问题:

我收到此错误

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
我不太清楚为什么我会这样,我从来没有经历过这个错误,我读过它,但不明白我的代码中会出现什么问题

问题:


很明显,为什么会出现这种错误?是什么原因造成的?

问题是,在insert查询中,您引用了一个maned参数
:code
,而在执行准备好的语句时,您使用了一个不正确的参数引用
生成的\u code
(完全没有冒号)。将该参数引用更改为
:code
,它应该可以工作


错误消息的意思与它所说的差不多,即未定义参数
生成的\u code

您的参数是
:code
,而不是
:生成的\u code
,就像您在
执行()
数组中所做的那样。哦,我明白了。非常感谢。