| Server IP : 127.0.0.1 / Your IP : 216.73.216.48 Web Server : Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 System : Windows NT DESKTOP-3H4FHQJ 10.0 build 19045 (Windows 10) AMD64 User : win 10 ( 0) PHP Version : 8.2.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/xampp/htdocs-coblaa/Cinevaa/ |
Upload File : |
<?php
session_start();
include 'db.php';
$error_msg = "";
// Ensure user is logged in
if (isset($_SESSION['my_id'])) {
$userID = $_SESSION['my_id'];
} else {
header("Location: login.php");
exit();
}
// Plan prices
$prices = [
'daily' => 1000,
'weekly' => 5000,
'monthly' => 20000
];
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['plan'])) {
$plan = $_POST['plan'];
// --- STEP 1: CHECK FOR AN EXISTING 'ACTIVE' PLAN ---
$checkSql = "SELECT expiry_date FROM cine_subscriptiontb WHERE my_id = ? AND subscription_status = 'active' AND expiry_date > NOW()";
$checkStmt = $con->prepare($checkSql);
$checkStmt->bind_param("s", $userID);
$checkStmt->execute();
$result = $checkStmt->get_result();
if ($result->num_rows > 0) {
$currentPlan = $result->fetch_assoc();
$error_msg = "You already have an active subscription valid until " . $currentPlan['expiry_date'];
} else {
// --- STEP 2: CALCULATE NEW EXPIRY ---
switch ($plan) {
case 'daily':
$expiryDate = date('Y-m-d H:i:s', strtotime('+1 day'));
break;
case 'weekly':
$expiryDate = date('Y-m-d H:i:s', strtotime('+7 days'));
break;
case 'monthly':
$expiryDate = date('Y-m-d H:i:s', strtotime('+1 month'));
break;
default:
die("Invalid Plan");
}
// --- STEP 3: CHECK IF USER RECORD EXISTS ---
$checkSql_two = "SELECT my_id FROM cine_subscriptiontb WHERE my_id = ?";
$stmt_two = $con->prepare($checkSql_two);
$stmt_two->bind_param("s", $userID);
$stmt_two->execute();
$res_two = $stmt_two->get_result();
if ($res_two->num_rows < 1) {
// INSERT new record
$sql = "INSERT INTO cine_subscriptiontb (my_id, subscription_status, expiry_date) VALUES (?, 'pending', ?)";
$stmt = $con->prepare($sql);
$stmt->bind_param("ss", $userID, $expiryDate);
} else {
// UPDATE existing record (Added WHERE clause to target only this user)
$sql = "UPDATE cine_subscriptiontb SET subscription_status = 'pending', expiry_date = ? WHERE my_id = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param("ss", $expiryDate, $userID);
}
if ($stmt->execute()) {
// Store details for the payment page
$_SESSION['selected_plan'] = $plan;
$_SESSION['amount'] = $prices[$plan] ?? 0;
// Redirect to payment
header("Location: payment_page.php");
exit();
} else {
$error_msg = "Database Error: " . $stmt->error;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Subscription Status</title>
<style>
body { background: #141414; color: white; font-family: sans-serif; text-align: center; padding-top: 50px; }
.card { background: #2f2f2f; display: inline-block; padding: 40px; border-radius: 10px; border-top: 5px solid #e50914; max-width: 400px; }
.btn { background: #e50914; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; display: inline-block; margin-top: 20px; font-weight: bold; }
.warning { color: #ffcc00; font-weight: bold; }
</style>
</head>
<body>
<div class="card">
<h1>Action Required</h1>
<?php if ($error_msg): ?>
<p class="warning"><?php echo $error_msg; ?></p>
<a href="index.php" class="btn">Back to Selection</a>
<?php else: ?>
<p>Processing your request...</p>
<?php endif; ?>
</div>
</body>
</html>