Advertisement
Guest User

Untitled

a guest
Dec 1st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2. // Include config file
  3. require_once 'config.php';
  4.  
  5. // Define variables and initialize with empty values
  6. $username = $password = "";
  7. $username_err = $password_err = "";
  8.  
  9. // Processing form data when form is submitted
  10. if($_SERVER["REQUEST_METHOD"] == "POST"){
  11.  
  12. // Check if username is empty
  13. if(empty(trim($_POST["username"]))){
  14. $username_err = 'Please enter username.';
  15. } else{
  16. $username = trim($_POST["username"]);
  17. }
  18.  
  19. // Check if password is empty
  20. if(empty(trim($_POST['password']))){
  21. $password_err = 'Please enter your password.';
  22. } else{
  23. $password = trim($_POST['password']);
  24. }
  25.  
  26. // Validate credentials
  27. if(empty($username_err) && empty($password_err)){
  28. // Prepare a select statement
  29. $sql = "SELECT username, password FROM users WHERE username = ? AND password = ?";
  30.  
  31. if($stmt = mysqli_prepare($link, $sql)){
  32.  
  33. mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
  34.  
  35. $param_username = $username;
  36. $param_password = $password;
  37. // Attempt to execute the prepared statement
  38. if(mysqli_stmt_execute($stmt)){
  39. // Store result
  40. mysqli_stmt_store_result($stmt);
  41.  
  42.  
  43. if(mysqli_stmt_num_rows($stmt) == 1){
  44. session_start();
  45. $_SESSION['username'] = $username;
  46. header("location: individ.html");
  47. } else{
  48.  
  49. $username_err = 'No account found with that username.';
  50. }
  51. } else{
  52. echo "Oops! Something went wrong. Please try again later.";
  53. }
  54. }
  55.  
  56. // Close statement
  57. mysqli_stmt_close($stmt);
  58. }
  59.  
  60. // Close connection
  61. mysqli_close($link);
  62. }
  63. ?>
  64.  
  65. <!DOCTYPE html>
  66. <html lang="en">
  67. <head>
  68. <meta charset="UTF-8">
  69. <title>Login</title>
  70. <link href="CSS/reset.css"
  71. rel="stylesheet"
  72. type="text/css">
  73.  
  74. <link href="CSS/main.css"
  75. rel="stylesheet"
  76. type="text/css">
  77.  
  78.  
  79. </head>
  80. <body style="background-image: url(a.jpg)">
  81.  
  82. <ul>
  83. <li><a class="active" href="index.html">Home</a></li>
  84. <li><a href="recept.html">Recepies</a></li>
  85. <li><a href="calender.html">Calender</a></li>
  86. <li><a href="file_name.php">Log in / Sign up</a></li>
  87. <li><a href ="signin.php">Sign in</a></li>
  88. </ul>
  89.  
  90. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  91. <div <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
  92. <label><b>Username:</b>
  93. <sup>*</sup></label>
  94. <input type="text" name="username"class="form-control" value="<?php echo $username; ?>">
  95. <span><?php echo $username_err; ?></span>
  96. </div>
  97. <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
  98. <label><b>Password:</b><sup>*</sup></label>
  99. <input type="password" name="password" class="form-control">
  100. <span ><?php echo $password_err; ?></span>
  101. </div>
  102. <div class="form-group">
  103. <input type="submit" class="btn btn-primary" value="Submit">
  104. </div>
  105.  
  106. </form>
  107.  
  108. </body>
  109. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement