Skorpius

Select Statement Structure (Placeholders)

Jun 24th, 2022 (edited)
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1.        
  2.         $sql = "SELECT * FROM users WHERE username = ? LIMIT 1";
  3.         $stmt = $pdo->prepare($sql);
  4.         $stmt->execute([$username]);
  5.  
  6.        while ($rows = $stmt->fetch(PDO::FETCH_ASSOC)){
  7.  
  8.              $id            = $rows['id'];
  9.              $uname         = $rows['username'];
  10.  
  11.              $_SESSION['id']            = $id;
  12.              $_SESSION['user']          = $uname;
  13.              header("Location: welcome.php");
  14.  
  15.        }
Add Comment
Please, Sign In to add comment