Skip to content

Instantly share code, notes, and snippets.

@psykzz
Created September 3, 2012 21:42
Show Gist options
  • Save psykzz/3613795 to your computer and use it in GitHub Desktop.
Save psykzz/3613795 to your computer and use it in GitHub Desktop.
function updateUser ($userID,$userData) {
$salt = $this::MD5_SALT;
if ($userData['password']=!"") {
$password = md5("{$salt}:{$userData['password']}");
$SQL =
"UPDATE `tblUsers`
SET `username`=?, `password`=?, `group`=? `access`=?
WHERE `user_id`=?;";
} else {
$SQL =
"UPDATE `tblUsers`
SET `username`=?, `group`=? `access`=?
WHERE `user_id`=?;";
}
if ($this->stmt = mysqli_prepare($this->link, $SQL)) {
if ($userData['password']=!"")
mysqli_stmt_bind_param($this->stmt, "ssi", $userData['username'], $userData['group'], $userData['access']);
else
mysqli_stmt_bind_param($this->stmt, "sssi", $userData['username'], $password, $userData['group'], $userData['access']);
mysqli_stmt_execute($this->stmt);
$assert = mysqli_stmt_affected_rows($this->stmt);
mysqli_stmt_close($this->stmt);
} else {
throw new Exception("Error preparing results",$this::MYSQLI_ERROR);
}
if ($assert>0)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment