You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
6 months ago
|
<?php
|
||
|
session_start();
|
||
|
|
||
|
// Check if the user is logged in
|
||
|
if (!isset($_SESSION["loggedInUser"])) {
|
||
|
header("Location: login.php");
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
// Database connection
|
||
|
$conn = new mysqli('localhost', 'root', '', 'user'); // Your database credentials
|
||
|
|
||
|
// Check connection
|
||
|
if ($conn->connect_error) {
|
||
|
die("Connection failed: " . $conn->connect_error);
|
||
|
}
|
||
|
|
||
|
$email = trim($_SESSION["loggedInUser"]);
|
||
|
|
||
|
// Fetch the user details from the registration table
|
||
|
$sql = "SELECT * FROM registration WHERE email = ?";
|
||
|
$stmt = $conn->prepare($sql);
|
||
|
$stmt->bind_param("s", $email);
|
||
|
$stmt->execute();
|
||
|
$result = $stmt->get_result();
|
||
|
|
||
|
// Get user details
|
||
|
if ($result->num_rows > 0) {
|
||
|
$user = $result->fetch_assoc();
|
||
|
$user_id = $user['id'];
|
||
|
} else {
|
||
|
echo "No user found.";
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
// Insert login date into user_streaks table
|
||
|
$today = date('Y-m-d');
|
||
|
|
||
|
// Check if the user logged in today
|
||
|
$checkStreak = $conn->query("SELECT * FROM user_streaks WHERE user_id = $user_id AND login_date = '$today'");
|
||
|
if ($checkStreak->num_rows == 0) {
|
||
|
// Insert new login date
|
||
|
$conn->query("INSERT INTO user_streaks (user_id, login_date) VALUES ($user_id, '$today')");
|
||
|
}
|
||
|
|
||
|
$stmt->close();
|
||
|
$conn->close();
|
||
|
?>
|