<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <title>Find Referral Code - Tbil Properties</title>
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">

<div class="container py-5">
  <div class="row justify-content-center">
    <div class="col-md-6">

      <div class="card shadow-lg border-0 rounded-3">
        <div class="card-body p-4">
          <h3 class="text-center mb-4">🔑 Find Your Referral Code</h3>

          <?php
          // Database connection
          $host = "localhost";
          $user = "root";
          $pass = "";
          $dbname = "savageboys";

          $conn = new mysqli($host, $user, $pass, $dbname);
          if ($conn->connect_error) {
              die("<div class='alert alert-danger'>Connection failed: " . $conn->connect_error . "</div>");
          }

          $message = "";

          if ($_SERVER["REQUEST_METHOD"] == "POST") {
              $email = mysqli_real_escape_string($conn, $_POST['email']);

              $sql = "SELECT referral_code FROM monosky WHERE email = '$email' LIMIT 1";
              $result = $conn->query($sql);

              if ($result->num_rows > 0) {
                  $row = $result->fetch_assoc();
                  $referral_code = $row['referral_code'];
                  $message = "<div class='alert alert-success text-center'>
                                🎉 Your Referral Code: <strong>$referral_code</strong>
                              </div>";
              } else {
                  $message = "<div class='alert alert-danger text-center'>
                                ❌ No referral code found for this email.
                              </div>";
              }
          }
          ?>

          <?php if (!empty($message)) echo $message; ?>

          <form method="post" action="">
            <div class="mb-3">
              <label for="email" class="form-label">Enter your registered Email</label>
              <input type="email" class="form-control" id="email" name="email" required>
            </div>
            <button type="submit" class="btn btn-primary w-100">Find Referral Code</button>
          </form>
        </div>
      </div>

    </div>
  </div>
</div>

<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
