Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1.  // Validate credentials
  2.         if ($unique_code_err == "") {
  3.             // Prepare a select statement
  4.             $sql = "SELECT id, unique_code FROM users WHERE unique_code = :unique_code";
  5.  
  6.             if ($stmt = $pdo->prepare($sql)) {
  7.                 // Bind variables to the prepared statement as parameters
  8.                 $stmt->bindParam(":unique_code", $param_unique_code, PDO::PARAM_INT);
  9.  
  10.                 // Set parameters
  11.                 $param_unique_code = trim($_POST["unique_code"]);
  12.  
  13.                 // Attempt to execute the prepared statement
  14.                 if ($stmt->execute()) {
  15.                     // Check if username exists, if yes then verify password
  16.                     if ($stmt->rowCount() == 1) {
  17.                         if ($row = $stmt->fetch()) {
  18.                             $id = $row["id"];
  19.                             $unique_code = $row["unique_code"];
  20.                                 // Password is correct, so start a new session
  21.                                 session_start();
  22.  
  23.                                 // Store data in session variables
  24.                                 $_SESSION["loggedin"] = true;
  25.                                 $_SESSION["guestloggedin"] = true;
  26.                                 $_SESSION["idguest"] = $id;
  27.                                 $_SESSION["unique_code"] = $unique_code;
  28.  
  29.                                 // Redirect user to welcome page
  30.                                 header("location: wishlist.php");
  31.                         }
  32.                     } else {
  33.                         // Display an error message if username doesn't exist
  34.                         $unique_code_err = "This unique code does not exist.";
  35.                     }
  36.                 } else {
  37.                     echo "Oops! Something went wrong. Please try again later.";
  38.                 }
  39.  
  40.                 // Close statement
  41.                 unset($stmt);
  42.             }
  43.         }
  44.  
  45.         // Close connection
  46.         unset($pdo);
  47.     }
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement