Guest User

Untitled

a guest
Jul 12th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. <?php
  2. $connect = new mysqli("localhost", "root", "Bismillah1", "capstone");
  3. if ($mysqli->connect_errno) {
  4. printf("Connection failed: %sn", $mysqli->connect_error);
  5. die();
  6. }
  7. session_start();
  8.  
  9. if(isset($_POST["Sign Up"]))
  10. {
  11. if(empty($_POST["Email"]) || empty($_POST["Password"]))
  12. {
  13. echo '<script> alert ("Both Feldsa are required)</script">';
  14. }
  15. else
  16. {
  17. $_SESSION['email'] = $_POST['Email'];
  18. $_SESSION['password'] = $_POST['Password'];
  19. $_SESSION['Repeatpassword'] = $_POST['Repeatpassword'];
  20. $_SESSION['name'] = $_POST['name'];
  21. $_SESSION['weight'] = $_POST['weight'];
  22. $_SESSION['feet'] = $_POST['feet'];
  23. $_SESSION['inches'] = $_POST['inches'];
  24. $_SESSION['age'] = $_POST['age'];
  25. $_SESSION['goal'] = $_POST['Goal'];
  26.  
  27.  
  28.  
  29. // Escape all $_POST variables to protect against SQL injection
  30. $email = $mysqli->escape_string($_POST['email']);
  31. $password = $mysqli->escape_string(password_hash($_POST['password'], PASSWORD_BCRYPT));
  32. $RepPassword = $mysqli->escape_string(password_hash($_POST['Repeatpassword'], PASSWORD_BCRYPT));
  33.  
  34.  
  35.  
  36.  
  37. $name = $mysqli->escape_string($_POST['name']);
  38. $Weight = $mysqli->escape_string($_POST['weight']);
  39. $feet = $mysqli->escape_string($_POST['feet']);
  40. $inches = $mysqli->escape_string($_POST['inches']);
  41. $age = $mysqli->escape_string($_POST['age']);
  42. $goal = $mysqli->escape_string($_POST['goal']);
  43. $hash = $mysqli->escape_string( md5( rand(0,1000) ) );
  44.  
  45.  
  46. // Check if user with that email already exists
  47.  
  48. // We know user email exists if the rows returned are more than 0
  49. $result = $mysqli->query("SELECT * FROM User WHERE Email_Address='$email'") or die($mysqli->error);
  50. if ( $result->num_rows > 0 ) {
  51.  
  52. $_SESSION['message'] = 'User with this email already exists!';
  53.  
  54.  
  55. }
  56. else { // Email doesn't already exist in a database, proceed...
  57.  
  58. // active is 0 by DEFAULT (no need to include it here)
  59. $sql = "INSERT INTO User (Email_Address, Password, Full Name, Weight, Feet, Inches, Age, Goal, hash) "
  60. . "VALUES ('$email', 'password', 'name' , 'Weight' , 'feet' , 'inches' , 'age' , 'goal', 'hash')";
  61. }
  62. if ( ! $mysqli->query($sql)
  63. {
  64. $_SESSION['message'] = 'Registration successfully';
  65. echo $_SESSION['message'];
  66.  
  67. header("location: loginaccount.html");
  68.  
  69. }
  70. }
  71.  
  72. else
  73. {$_SESSION['message'] = 'Registration failed!';
  74. echo $_SESSION['message'];
  75.  
  76. }
  77. }
  78. ?>
  79.  
  80. <?php
  81. if(isset($_POST["login"]))
  82. {
  83. $email = $mysqli->escape_string($_POST['Email']);
  84. $result = $mysqli->query("SELECT * FROM User WHERE Email_Address='$email'");
  85. if ( $result->num_rows == 0 ) { //
  86. {
  87. $_SESSION['message'] = "User with that email doesn't exist!";
  88. echo $_SESSION['message'];
  89. }
  90. else {
  91. $user = $result->fetch_assoc();
  92. if ( password_verify($_POST['password'], $user['Password']) ) {
  93. $_SESSION['email'] = $user['Email_Address'];
  94. $_SESSION['name'] = $user['Full Name'];
  95. $_SESSION['weight'] = $user['Weight '];
  96.  
  97. $_SESSION['feet'] = $user['Feet '];
  98. $_SESSION['inches'] = $user['Inches '];
  99. $_SESSION['age'] = $user['Age '];
  100. $_SESSION['goal'] = $user['Goal '];
  101. $_SESSION['logged_in'] = true;
  102. $_SESSION['active'] = $user['Active'];
  103. header("location: loginaccount.html");
  104.  
  105.  
  106. }
  107. }
  108.  
  109. ?>
  110. //<p align ="center"><a href="Register.php">Register</a></p>
  111.  
  112. I have included the php file in my html file in the following way, I believe the code is right
  113.  
  114. <!DOCTYPE html>
  115. <html lang="en" dir="ltr">
  116.  
  117. <?php include 'Caplogin.php';?>
  118. <head>
  119. <meta charset="utf-8">
  120. <meta name="viewport" content = "width=device-width">
  121. <meta name="description" content="A place where people can take
  122. fitness to the next level">
  123. <title>Swole Summer | Account Creation </title>
  124. <link rel = "stylesheet" href ="./css/style.css">
  125. </head>
Add Comment
Please, Sign In to add comment