-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthenticate.php
More file actions
38 lines (30 loc) 路 1.21 KB
/
Copy pathauthenticate.php
File metadata and controls
38 lines (30 loc) 路 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// Start the session
session_start();
// Database connection
$conn = new mysqli('localhost', 'root', '', 'Fitnessgym'); // Adjust the credentials if needed
// Check for database connection errors
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the username and password from the POST request
$username = $_POST['username'];
$password = $_POST['password']; // Plain text password from form
// SQL query to fetch user by username and password
$sql = "SELECT * FROM Users WHERE name = '$username' AND password = '$password'";
// Execute the query
$result = $conn->query($sql);
// Check if a user with the provided username and password exists
if ($result->num_rows > 0) {
// Start the session for the authenticated user
$_SESSION['user'] = $username; // You can store other user info if necessary
// Redirect to HOME.html
header("Location: HOME.html");
exit(); // Make sure to stop the script execution after redirection
} else {
// If login is not successful, alert the user and redirect back to login
echo "<script>alert('Invalid username or password'); window.location.href = 'login.html';</script>";
}
// Close the database connection
$conn->close();
?>