forked from yashasvi211/shopcity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
35 lines (29 loc) · 849 Bytes
/
login.php
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
<?php
$conn = mysqli_connect('localhost', 'root', '', 'shopcity');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// process login form
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST["email"];
$password = $_POST["password"];
// retrieve user data from the database
$sql = "SELECT * FROM users WHERE email='$email'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if (password_verify($password, $row["password"])) {
echo "Login successful!";
// redirect to home.php
header("Location: home.php");
exit();
} else {
echo "Incorrect password!";
}
} else {
echo "User not found!";
}
}
// Close connection
$conn->close();
?>