<?php
// Database connection
$host = "localhost";
$username = "job_portal";
$password_db = "job_portal"; // XAMPP default
$dbname = "job_portal";

$conn = new mysqli($host, $username, $password_db, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Collect POST values safely
function get_post($key) {
    return isset($_POST[$key]) ? trim($_POST[$key]) : null;
}

$entry_date         = get_post('entry_date');
$member_return_date = get_post('member_return_date');
$applicant_name     = get_post('applicant_name');
$applicant_title    = get_post('applicant_title');
$address            = get_post('address');
$country            = get_post('country');
$post_code          = get_post('post_code');
$phone_home         = get_post('phone_home');
$phone_work         = get_post('phone_work');
$mobile_no          = get_post('mobile_no');
$fax                = get_post('fax');
$email              = get_post('email');
$unit_type          = get_post('unit_type');
$season             = get_post('season');
$no_weeks           = (int)get_post('no_weeks');
$occupancy_years    = (int)get_post('occupancy_years');
$purchase_price     = (float)get_post('purchase_price');
$membership_type    = get_post('membership_type');
$tenure             = get_post('tenure');
$deposit            = (float)get_post('deposit');
$payment_mode       = get_post('payment_mode');
$balance            = (float)get_post('balance');
$hotel_place        = get_post('hotel_place');
$room_no            = get_post('room_no');
$remarks            = get_post('remarks');
$quota_applied      = isset($_POST['quota_applied']) ? 1 : 0;
$client_approval    = isset($_POST['client_approval']) ? 1 : 0;
$manager_approval   = isset($_POST['manager_approval']) ? 1 : 0;
$password           = get_post('Password');  // **Note:** Make sure your form uses 'Password' as field name (case-sensitive)
$consultant_name    = get_post('consultant_name');
$manager_name       = get_post('manager_name');

// **Remove this hashing line**
// $hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Prepare SQL insert
$sql = "INSERT INTO memberships (
  entry_date, member_return_date, applicant_name, applicant_title, address,
  country, post_code, phone_home, phone_work, mobile_no, fax, email,
  unit_type, season, no_weeks, occupancy_years, purchase_price,
  membership_type, tenure, deposit, payment_mode, balance,
  hotel_place, room_no, remarks, quota_applied, client_approval,
  manager_approval, password, consultant_name, manager_name
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$stmt = $conn->prepare($sql);

$stmt->bind_param(
    "ssssssssssssssiidssdsdsssiiisss",
    $entry_date, $member_return_date, $applicant_name, $applicant_title, $address,
    $country, $post_code, $phone_home, $phone_work, $mobile_no, $fax, $email,
    $unit_type, $season, $no_weeks, $occupancy_years, $purchase_price,
    $membership_type, $tenure, $deposit, $payment_mode, $balance,
    $hotel_place, $room_no, $remarks, $quota_applied, $client_approval,
    $manager_approval, $password,  // <- seedha yahan $password bhej rahe hain
    $consultant_name, $manager_name
);

if ($stmt->execute()) {
    echo "<h3>✅ Membership successfully inserted!</h3>";
    echo "<p><strong>Entered Password:</strong> " . htmlspecialchars($password) . "</p>";
} else {
    echo "❌ Error: " . $stmt->error;
}

$stmt->close();
$conn->close();
?>
