Advertisement
Guest User

Untitled

a guest
Apr 14th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. require("database.php");
  4.  
  5. // User class
  6. class user {
  7.  
  8. // Attributes
  9. public $uid,$ucognome,$unome,$uemail,$utel;
  10.  
  11. private $db = null;
  12.  
  13. function __construct() {
  14. $this->db = new Database();
  15. }
  16.  
  17. // Insert user
  18. public function insert(){
  19. $sql = "INSERT INTO users (cognome,nome,email,telefono)
  20. VALUES('".$this->ucognome."', '".$this->unome."','".$this->uemail."'
  21. ,'".$this->utel."')";
  22.  
  23. $this->db->run($sql);
  24.  
  25. }
  26.  
  27.  
  28.  
  29. // Delete user
  30. public function delete(){
  31. $sql = "DELETE FROM users WHERE id=". $this->uid;
  32. $this->db->run($sql);
  33. }
  34.  
  35.  
  36. // Update user
  37. public function update(){
  38. $sql = "UPDATE users SET cognome= '".$this->ucognome."',
  39. nome='".$this->unome."',
  40. email='".$this->uemail."',
  41. telefono='".$this->utel."'
  42.  
  43. WHERE id ='".$this->uid."'";
  44.  
  45. $this->db->run($sql);
  46. }
  47.  
  48. // Display users
  49. public function display(){
  50.  
  51. $temp_arr = array();
  52.  
  53. $res = $this->db->run("SELECT * FROM users ORDER by cognome,nome ");
  54. $count=$this->db->rowCount();
  55. while($row = $this->db->fetchArray()) {
  56. $temp_arr[] =$row;
  57. }
  58. return $temp_arr;
  59.  
  60. }
  61.  
  62.  
  63. // get id upload
  64. public function getid(){
  65. $db = new mysqli("localhost","root","", "rubrica");
  66. if ($db-> connect_errno) {
  67. exit();
  68. }
  69. $nome = $this->unome;
  70. $cognome = $this->ucognome;
  71. $email = $this->uemail;
  72. $telefono = $this->utel;
  73. $query = $db->query("SELECT id FROM users WHERE nome='$nome' and cognome='$cognome' and email='$email' and telefono='$telefono'");
  74. $id = $query->fetch_assoc()['id'];
  75. $db->close();
  76. return $id;
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. // Get user by id (update)
  86. public function getUserById($uid){
  87. $temp_arr = array();
  88.  
  89. $res = $this->db->run("SELECT * FROM users WHERE id=$uid");
  90.  
  91. $userDetails = $this->db->fetchArray();
  92.  
  93. return $userDetails;
  94. }
  95. }
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement