0

I have a simple problem whitch I can't solve, because I am starting with OOP and in the same time with MySQLi.

I need these function universal for everything and I need SET statement dynamically changed.

This is my update function these not working

public function updateUser($user, $pass, $dbSet) {   
  if($this->getUser($user, $pass) != NULL) {      
    $sql = $this->connection->prepare("UPDATE users SET ? WHERE user = ?");

    $sql->bind_param('ss', $dbSet, $user);
    $sql->execute();   
    $sql->close(); 

    return true;
  } else {
    return false;
  }   
}

Variable $dbSet contains different values. For example:

$dbSet = "last_activity = ".$last_activity;

Or complex

$dbSet = "name = ".$newName.", surname = ".$newSurname.", email = ".$newEmail;

But when I change it for one SET statement, it works...

...         
$sql = $this->connection->prepare("UPDATE users SET last_activity = ? WHERE user = ?");         
...
Dharman
  • 30,962
  • 25
  • 85
  • 135

0 Answers0