有人在这里帮助我:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

public function register($uname,$age,$sex,$image,$dpart,$joind,$job,$uposition,$phone,$umail,$upass,
                             $unumber,$address,$nssf,$bank,$passp,$home,$village,$nation,$permit)
    {
        try
        {
            $new_password = password_hash($upass, PASSWORD_DEFAULT);

            $stmt = $this->conn->prepare("INSERT INTO users(user_name,birth,gender,image,job_title,curr_position,telephone,department,joining_date,user_email,user_pass,box_number,residence,nssf_number,bank_account,passport_number,home_district,village,nationality,work_permit) 
                                                       VALUES(:uname,:age,:sex,:image,:dpart,:joind,:job,:uposition,:phone,:umail,:upass,:unumber,:nssf,:bank,:passp,:home,:village,:nation,:permit)");

            $stmt->bindparam(":uname",$uname);
            $stmt->bindparam(":age",$age);
            $stmt->bindparam(":sex",$sex);
            $stmt->bindparam(":image",$image);
            $stmt->bindparam(":dpart",$dpart);
            $stmt->bindparam(":joind",$joind);
            $stmt->bindparam(":job",$job);
            $stmt->bindparam(":uposition",$uposition);
            $stmt->bindparam(":phone",$phone);
            $stmt->bindparam(":umail",$umail);
            $stmt->bindparam(":upass",$new_password);
            $stmt->bindparam(":unumber",$unumber);
            $stmt->bindparam(":address",$address);
            $stmt->bindparam(":nssf",$nssf);
            $stmt->bindparam(":bank",$bank);
            $stmt->bindparam(":passp",$passp);
            $stmt->bindparam(":home",$home);
            $stmt->bindparam(":village",$village);
            $stmt->bindparam(":nation",$nation);
            $stmt->bindparam(":permit",$permit);

            $stmt->execute();   

            return $stmt;   
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }               
    }

I'm posting this as a community wiki answer, since there shouldn't be any rep from this, nor do I want rep from it; given an answer that can't determine which one is missing.

It's the one for $stmt->bindparam(":address",$address); that is missing in the VALUES().

Also make sure that all variables do contain value.

PHP's error reporting will be of help:

Side note: Using a code editor that automatically finds matching words when double-clicked and using the same naming convention would have helped you greatly.

  • One (free) of which that has option, is Notepad++.
  • Your sql statement is inconsistent: the table columns and the values to insert don't correspond. For example, in a curr_position field you are trying to insert a value of :joind, etc.
  • Also, in terms of number, the columns and the values to insert don't coincide: 19 values to insert in 20 fields.

Recommendations:

My recommendation would be to always use column names for the marker names. Then you know exactly to which markers you are inserting the corresponding values.

NB: Markers: "...VALUES (:marker1, :marker2, ...);".

You should also define the type of input parameteres that you are binding. Example:

$stmt->bindparam(":age", $age, PDO::PARAM_INT);

Try to maintain some consistency between the function parameters and the field names, if it's possible and... makes sense.

My code proposal would look like this:

<?php

public function register(
    $userName
    , $birth
    , $gender
    , $image
    , $jobTitle
    , $currPosition
    , $telephone
    , $department
    , $joiningDate
    , $userEmail
    , $userPass
    , $boxNumber
    , $residence
    , $nssfNumber
    , $bankAccount
    , $passportNumber
    , $homeDistrict
    , $village
    , $nationality
    , $workPermit
) {
    try {
        $newUserPassword = password_hash($userPass, PASSWORD_DEFAULT);

        $stmt = $this->conn->prepare('INSERT INTO users (
                                            user_name,
                                            birth,
                                            gender,
                                            image,
                                            job_title,
                                            curr_position,
                                            telephone,
                                            department,
                                            joining_date,
                                            user_email,
                                            user_pass,
                                            box_number,
                                            residence,
                                            nssf_number,
                                            bank_account,
                                            passport_number,
                                            home_district,
                                            village,
                                            nationality,
                                            work_permit
                                        ) VALUES (
                                            :user_name,
                                            :birth,
                                            :gender,
                                            :image,
                                            :job_title,
                                            :curr_position,
                                            :telephone,
                                            :department,
                                            :joining_date,
                                            :user_email,
                                            :user_pass,
                                            :box_number,
                                            :residence,
                                            :nssf_number,
                                            :bank_account,
                                            :passport_number,
                                            :home_district,
                                            :village,
                                            :nationality,
                                            :work_permit
                                        )');

        $stmt->bindparam(":user_name", $userName, PDO::PARAM_STR);
        $stmt->bindparam(":birth", $birth, PDO::PARAM_INT);
        $stmt->bindparam(":gender", $gender, PDO::PARAM_STR);
        $stmt->bindparam(":image", $image, PDO::PARAM_STR);
        $stmt->bindparam(":job_title", $jobTitle, PDO::PARAM_STR);
        $stmt->bindparam(":curr_position", $currPosition, PDO::PARAM_STR);
        $stmt->bindparam(":telephone", $telephone, PDO::PARAM_STR);
        $stmt->bindparam(":department", $department, PDO::PARAM_STR);
        $stmt->bindparam(":joining_date", $joiningDate, PDO::PARAM_STR);
        $stmt->bindparam(":user_email", $userEmail, PDO::PARAM_STR);
        $stmt->bindparam(":user_pass", $newUserPassword, PDO::PARAM_STR);
        $stmt->bindparam(":box_number", $boxNumber, PDO::PARAM_INT);
        $stmt->bindparam(":residence", $residence, PDO::PARAM_STR);
        $stmt->bindparam(":nssf_number", $nssfNumber, PDO::PARAM_INT);
        $stmt->bindparam(":bank_account", $bankAccount, PDO::PARAM_STR);
        $stmt->bindparam(":passport_number", $passportNumber, PDO::PARAM_STR);
        $stmt->bindparam(":home_district", $homeDistrict, PDO::PARAM_STR);
        $stmt->bindparam(":village", $village, PDO::PARAM_STR);
        $stmt->bindparam(":nationality", $nationality, PDO::PARAM_STR);
        $stmt->bindparam(":work_permit", $workPermit, PDO::PARAM_STR);

        $stmt->execute();

        return $stmt;
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
}

Good luck!

Thank you all for your efforts and input i figured out the problem actually was this one:
$stmt->bindParam("userPass", $newUserPassword, PDO::PARAM_STR); which had to be changed to this: $stmt->bindParam("userPass", $userPass, PDO::PARAM_STR); I was trying to use a parameter that i had not defined all because i di this: $newUserPassword = password_hash($userPass, PASSWORD_DEFAULT); So I thought of replacing it in the bindParameters....Hope it helps other!