hi i just came here if theres someone who coudl help me with my problem whenever i add a new user this keeps on appearing\
"INSERT INTO teacher_info (firstname,middlename,lastname,gender,address,date_joined,username,password) VALUES ('John','Doe','Doenut','Male','New york USA','2021-06-11','john','admin')
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\classroom\vendor\controllers\teacherClass\teacherclass.php:22 Stack trace: #0 C:\xampp\htdocs\classroom\vendor\controllers\teacherClass\teacherclass.php(22): PDOStatement->execute(Array) #1 C:\xampp\htdocs\classroom\vendor\controllers\teacherClass\store.php(18): Teacher->addTeacher(Array) #2 {main} thrown in C:\xampp\htdocs\classroom\vendor\controllers\teacherClass\teacherclass.php on line 22"

store.php
<?php 
//create instance
include 'teacherclass.php';

if($_POST){

    $register = new Teacher();

    $register->addTeacher([

        'firstname'=>$_POST['firstname'],
        'middlename'=>$_POST['middlename'],
        'lastname'=>$_POST['lastname'],
        'gender'=>$_POST['gender'],
        'address'=>$_POST['address'],
        'date_joined'=>$_POST['date_joined'],
        'username'=>$_POST['username'],
        'password'=>$_POST['password'],

    ]);

}


?>



TEacher Class.php
<?php 

include '../dbclass/dbconn.php';

class Teacher extends Dbh {

    public $connection;
    public $sql;
    public $table = 'teacher_info';

    function addTeacher( $values){

              //sql statement
              $sql = " INSERT INTO ". $this->table ." (" ;
              $sql .= implode(",",array_keys($values)) .') VALUES (';
              echo $sql .= "'" . implode("','", array_values($values)) . "')";

              // sql statement query
              $stmt = $this->connection()->prepare($sql);

              //execution of function
              $stmt->execute($values);


    }

}

?>

Line 19 ends with a comma. This might insert an empty item into your array, messing up the build of your query. Remove it and try again.

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.