Hi all, I'm quite a new developer, and I've spent a long time trying to figure out what is causing this error: "SQLSTATE[HY093]: Invalid parameter number: parameter was not defined"

As far as I can tell, all my parameters are defined?

My code is below:

$mySQL_query = "INSERT INTO vd_users (
                        username,
                        password,
                        salt,
                        pin,
                        pin_salt,
                        r_date)
                VALUES (
                        :username,
                        :password,
                        :salt,
                        :pin,
                        :pin_salt,
                        :r_date)";

$mySQL_query_parameters = array(
        ':username'         => $_POST['username'],
        ':password'         => $password,
        ':password_salt'    => $password_salt,
        ':pin'              => $pin,
        ':pin_salt'         => $pin_salt,
        ':r_date'           => $datetime
        );

try {
        $mySQL_statement = $mySQL_connection->prepare($mySQL_query);
        $mySQL_result = $mySQL_statement->execute($mySQL_query_parameters);
        }

catch(PDOException $mySQL_errors) {
    die($mySQL_errors->getMessage();
    }

Can anyone help me figure this out?

Hi James,

I think you need to give same name to the 'salt' parameter. You have named it 'salt' in query and 'password_salt' when setting parameters.

Hope it helps.

Cheers.

Ah, such a basic mistake. Thanks for pointing that out, would have taken me hours on my own! :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.