0

This is not working for some reason, same loop works fine with a SELECT statement but not an INSERT statement.

 $sql = "INSERT INTO users(user_id,password) VALUES(?,?)";
 $data = array();
 $data[1] = "1";
 $data[2] = "password";
 public function insert($sql,$data){
    $newQuery = $this->db->prepare($sql);
    //pass $value as a reference to the array item
    foreach ($data as $key => &$value) {  
    // bind the variable to the statement
        $newQuery->bindParam($key,$value); 
    } 
    $newQuery->execute();
}
Jerin Oommen
  • 45
  • 1
  • 7

0 Answers0