Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(isset($_POST['login'])) {
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $password = mysqli_real_escape_string($db, $_POST['password']);
- // Ensure that form fields are filled properly
- if(empty($username)) {
- array_push($errors, "Username is required!");
- }
- if(empty($password)) {
- array_push($errors, "Password is required!");
- }
- if(count($errors) == 0){
- $password = md5($password); // Encrypt password before comparing this one with the one in database
- $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
- $result = mysqli_query($db, $query);
- if (mysqli_num_rows($result) == 1) {
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now logged in";
- header('location: ../system.php'); // Redirect to main page location
- } else {
- array_push($errors, "Wrong username/password combination");
- header('location: ../php/login.php');
- }
- }
- }
Add Comment
Please, Sign In to add comment