MySQL - DriverError { Statement takes 4 parameters but 2 was supplied }

I've got the following piece of code which compiles:

pub fn add_user(&self, data: RegistrationForm) -> bool {
            let mut conn = self.conn.get_conn().unwrap();

            let execute_result = conn.exec_batch("
            INSERT INTO users (
                username, email, birthdate, password
            ) VALUES (
                :username, :email, :birthdate, :password
            )", params! {
                "username" => &data.username,
                "email" =>,
                "birthdate" => data.birthdate,
                "password" => data.password

            match execute_result {
                Ok(_) => {
                    println!("User {} added!", data.username);
                Err(e) => {
                    eprintln!("Failed to add user {}: {}", data.username, e.to_string());

I'm sure that data.username,, data.birthdate, data.password ain't empty. For some reason I get the following error at runtime;

Failed to add user test: DriverError { Statement takes 4 parameters but 2 was supplied }

I guess this has something to do with the prepared statement failing. But I don't see how it could fail?

Bump for help.

It would probably help if you specified some additional details, like which crate you’re using to access the database. Is it possible that the username and password parameters are being interpreted as access credentials instead of parameter bindings?

Edit: Also, I hope those passwords aren’t going into the database in plaintext; that’s a security nightmare waiting to happen.

I'm using the mysql crate:

Pretty sure it's a bug in the crate. Can't find a solution for two days now. Documentation is insufficient as well.

I don't advice it. Trying Diesel.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.