SHARE
TWEET

Untitled

a guest Oct 4th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. methods
  2. /////////////////////////////////////////////////////////////////////////////////
  3. public static function find_by_id($uid=0){
  4.         // return an object populated based on user id
  5.         global $database;
  6.         $user = new User();
  7.        
  8.         $sql = "SELECT * FROM users ";
  9.         $sql .= "WHERE  id=${uid} ";
  10.         $sql .= "LIMIT 1";
  11.        
  12.         $result = $database->query($sql);
  13.    
  14.         if($database->num_rows($result)){
  15.             $row = $database->fetch_assoc($result);
  16.             $user->username = $row['username'];
  17.             $user->password = $row['password'];
  18.             $user->id = $uid;
  19.         }
  20.        
  21.         return $user;
  22.  
  23. }
  24.  
  25. public function update(){
  26.  
  27.         global $database;
  28.    
  29.         $sql = "UPDATE users ";
  30.         $sql .= "SET username = '" . $user->username . "' password = '" .  $user->password . "' ";
  31.         $sql .= "WHERE id ='" . $user->id;
  32.        
  33.         $result = $database->query($sql);
  34.        
  35.         return $result;
  36.    
  37. }
  38.  
  39. ///////////////////////////////////////////////////////////////////////////
  40.  
  41. update.php
  42.  
  43. <?php
  44. require_once('database.php');
  45. require_once('user.php');
  46.  
  47. $user = User::find_by_id($_GET['id']);
  48.  
  49. if(isset($_POST['submit'])){
  50.     $user->id = $_GET['id'];
  51.     $user->update();
  52.  
  53. }
  54.  
  55. <form action="update.php?id=<?php echo $user->id; ?>" method="post">
  56.     <label for="username">Username</label>
  57.     <input type="text" name="username" value="<?php echo $user->username; ?>" />
  58.     <label for="password">Password</label>
  59.     <input type="password" name="password" value="<?php echo $user->password; ?>" />
  60.     <input type="submit" value="Update" name="submit">
  61. </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top