so I was following a Udemy course and then the instructor made this function
public function update($table, $user_id, $fields = array()){
$columns = '';
$i = 1;
foreach($fields as $name => $value){
$columns .= "'{$name}' = :{$name}";
if($i < count($fields)){
$columns .= ', ';
}
$i++;
}
$sql = "UPDATE {$table} SET {$columns} WHERE 'user_id' = {$user_id}";
if($stmt = $this->pdo->prepare($sql)){
foreach($fields as $key => $value){
$stmt->bindValue(':'.$key, $value);
}
$stmt->execute();
}
}
And I wrote it literally so many times after him and it just never seemed to work, would someone explain for me what's wrong with the code?