0

I have Registration class and here I have defined public function insert and in bindParam function line I'm getting error message which is :

Fatal error: Uncaught Error: Only variables can be passed by reference

public function insert ( $table, $coloumns, $values, string $where = null, string $whereValue = null )
    {
        global $db; 
        $tbl_columns = array(); 
        foreach ($coloumns as $key => $value) {
            $tbl_columns[] = ":{$value}";
        }       
        $tbl_columns = implode(', ', $tbl_columns);     
        $values = implode(',', $values);

        $coloumns2 =  implode(',', $coloumns);

        $sql = " INSERT INTO $table ( $coloumns2 ) VALUES ( $tbl_columns )";
        if($where && $whereValue) {
            $sql .= " WHERE $where = '$whereValue' ";
        }
        $stm = $db->prepare($sql);
        foreach ($coloumns as $key => $value) {
            $stm->bindParam(":{$value}", $values[$key]);
        }           

        return $sql;
    }
shibbir ahmed
  • 1,014
  • 2
  • 18
  • 34

0 Answers0