Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. public function getById($id)
  2. {
  3. $res = $this->conn->query("SELECT * FROM {$this->tbl} WHERE id = $id");
  4. if ($res->num_rows > 0) {
  5. $user = $res->fetch_assoc();
  6. return $user;
  7. }
  8. return false;
  9. }
  10.  
  11. public function update($data)
  12. {
  13. $user = $this->getById($data['user_id']);
  14. if ($user['username'] == $data['username']) {
  15. $username = $data['username'];
  16. $data['username'] = false;
  17. } else {
  18. $username = $data['username'];
  19. }
  20. if ($data['password'] == null) {
  21. $password = $data['password2'];
  22. $data['password'] = false;
  23. } else {
  24. $password = md5($data['password']);
  25. }
  26. $validasi = $this->_validasi($data);
  27. if ($validasi == []) {
  28. $res = $this->conn->query("UPDATE {$this->tbl} SET nama='{$data['nama']}',username='{$username}',password='{$password}',email='{$data['email']}' WHERE id={$data['user_id']}");
  29. $this->conn->close();
  30. return $res;
  31. } else {
  32. return $validasi;
  33. }
  34. }
  35.  
  36. public function delete($id)
  37. {
  38. $this->conn->query("DELETE FROM {$this->tbl} WHERE id = {$id}");
  39. if ($this->conn->affected_rows == 1) {
  40. return true;
  41. }
  42. return false;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement