-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticate.php
More file actions
46 lines (30 loc) · 793 Bytes
/
Copy pathauthenticate.php
File metadata and controls
46 lines (30 loc) · 793 Bytes
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
39
40
41
42
43
44
45
46
<?php
include("db.php");
session_start();
// Ensure $conn is defined (fallback to local mysqli if db.php didn't set it)
if (!isset($conn) || !($conn instanceof mysqli)) {
$conn = new mysqli('localhost', 'root', '', '');
if ($conn->connect_error) {
die('Database connection failed: ' . $conn->connect_error);
}
}
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users
WHERE username=?
AND password=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if(mysqli_num_rows($result)==1){
$_SESSION['username']=$username;
header("Location: dashboard.php");
}
else{
echo "<script>
alert('Invalid Username or Password');
window.location='login.php';
</script>";
}
?>