Advertisement
Guest User

Untitled

a guest
May 4th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2. require_once 'Classes/ClassUser.php';
  3. require_once 'DBconnect.php';
  4.  
  5. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  6. if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['username'])) {
  7.  
  8. $mail = $_POST['email'];
  9. $pas = $_POST['password'];
  10. $uName = $_POST['username'];
  11.  
  12. $user = new User();
  13. $user->setEmail($mail);
  14. $user->setUsername($uName);
  15. $user->setHashPass($pas);
  16. $a = $user->saveToDB($conn);
  17.  
  18. session_start();
  19. $sql = "SELECT id FROM users WHERE email ='$mail' and hash_pass = '$pas'";
  20.  
  21. $result = $conn->query($sql);
  22. var_dump($result);
  23. // $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  24. $row = $result->fetch(PDO::FETCH_ASSOC);
  25. var_dump($row);
  26.  
  27.  
  28. $count = count($result);
  29. var_dump($count);
  30.  
  31. // If result matched $myusername and $mypassword, table row must be 1 row
  32.  
  33. if($count == 1 && $row != false) {
  34. $_SESSION['login_userId'] = $row['id'];
  35.  
  36. header("location: HomePage.php");
  37. }else {
  38. $error = "Your Login Name or Password is invalid";
  39. echo $error;
  40. }
  41. }
  42.  
  43.  
  44. }
  45. ?>
  46. <!DOCTYPE html>
  47. <html lang="en">
  48. <head>
  49. <meta charset="UTF-8">
  50. <title>Title</title>
  51. </head>
  52. <body>
  53. <h2>Rejestracja</h2>
  54. <form action="" method="post">
  55. Podaj nazwę użytkownika :
  56. <input type="text" name="username"> </input>
  57. Podaj adres email :
  58. <input type="text" name="email"> </input>
  59. Podaj hasło :
  60. <input type="text" name="password"> </input>
  61. <button type="submit">Zarejestruj się</button>
  62.  
  63. </form>
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement