简体   繁体   中英

How to fix “mysqli_stmt::bind_param():” on modification to mysql databas

I am creating a user registration system, and I am at the point where I start modifying the database i get the error "Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in /opt/lampp/htdocs/Projectss/01_sarah/index.php on line 41 "

I have tried using every single method in php documentation concerning adding data to the database

here is some code

       $hash_password = password_hash($password, PASSWORD_DEFAULT);

        $query = "INSERT INTO users (first_name,last_name,email,password) VALUES('$first_name','$last_name','$email','$hash_password')";

        $stmt = $conn->prepare($query);
        if (!$stmt) {
            echo mysqli_error($conn);
        }
        $stmt->bind_param('ssss', $query);
        $stmt->execute(); // execute prepared statement
        $conn->close(); // close connection

    }

The expected result should is to not receive any warning after saving the information to the database

You're passing complete query in the bindParam and also passing the values in the query instead of this you need to pass the parameters in the bindParam like this..

       $hash_password = password_hash($password, PASSWORD_DEFAULT);

    $query = "INSERT INTO users (first_name,last_name,email,password) VALUES(?, ?, ?, ?)";

    $stmt = $conn->prepare($query);
    $stmt->bind_param('ssss', $first_name, $last_name, $email, $hash_password);
    $stmt->execute(); // execute prepared statement
    $conn->close(); // close connection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM