File: /srv/www/rectt-csmcri.res.in/public_html/process_primary.php
<?php
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
ob_start();
session_start();
include_once 'sites/config/config.php';
if (!isset($_SESSION['registered'])) {
header("location:login.php");
}
if ($_SESSION['primary_saved'] == "Yes") {
header("location:dashboard.php");
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header("Location: primary.php");
exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!isset($_SESSION['user_id'], $_SESSION['session_token'])) {
session_destroy();
header("Location: logout.php");
exit;
}
$user_id = $_SESSION['user_id'];
$token = $_SESSION['session_token'];
$stmt = $conn->prepare("SELECT session_token FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$stmt->bind_result($db_token);
$stmt->fetch();
$stmt->close();
if ($token !== $db_token) {
session_destroy();
die("You have been logged out because your account was logged in elsewhere.");
}
// $user_id = $_SESSION['user_id']; // Get the ID of the newly inserted user
$ssc_name = $_POST['name'];
$has_name_changed = $_POST['name_changed'];
$new_name = ($has_name_changed == 'Yes') ? $_POST['new_name'] : NULL;
$mother_name = $_POST['mother_name'];
$father_name = $_POST['father_name'];
// $dob = $_POST['dob'];
// Make sure date is in correct format
$dob = date('Y-m-d', strtotime($_POST['dob']));
$age = $_POST['age_input'];
$place_ob = $_POST['place_of_birth'];
$citizenship = "Indian";
$gender = $_POST['gender'];
// $religion = $_POST['religion'];
if ($_POST['religion'] == 'Other') {
$religion = $_POST['otherReligion'];
} else {
$religion = $_POST['religion'];
}
$disability = $_POST['disability'];
// $disability_hearing = ($disability == 'Yes') ? $_POST['disability_hearing'] : NULL;
// $disability_walking = ($disability == 'Yes') ? $_POST['disability_walking'] : NULL;
// $disability_multiple = ($disability == 'Yes') ? $_POST['disability_multiple'] : NULL;
$disability_walking = isset($_POST["disability_walking"]) ? $_POST["disability_walking"] : NULL;
$disability_hearing = isset($_POST["disability_hearing"]) ? $_POST["disability_hearing"] : NULL;
$disability_multiple = isset($_POST["disability_multiple"]) ? $_POST["disability_multiple"] : NULL;
$category = $_POST['category'];
$ex_servicemen = $_POST['exServicemen'];
$service_years = ($ex_servicemen == 'Yes') ? $_POST['serviceYears'] : NULL;
$service_months = ($ex_servicemen == 'Yes') ? $_POST['serviceMonths'] : NULL;
$service_days = ($ex_servicemen == 'Yes') ? $_POST['serviceDays'] : NULL;
$gov_employee = $_POST['govEmployee'];
$gov_organization = ($gov_employee == 'Yes') ? $_POST['govOrganization'] : NULL;
$gov_post = ($gov_employee == 'Yes') ? $_POST['govPost'] : NULL;
$csir_employee = $_POST['csirEmployee'];
$csir_lab = ($csir_employee == 'Yes') ? $_POST['csirInstitute'] : NULL;
$csir_designation = ($csir_employee == 'Yes') ? $_POST['csirDesignation'] : NULL;
$marital_status = $_POST['maritalStatus'];
$staying_abroad = $_POST['stayingAbroad'];
$corr_house = $_POST['corr_house'];
$corr_state = $_POST['corr_state'];
$corr_city = $_POST['corr_city'];
$corr_district = $_POST['corr_district'];
$corr_pincode = $_POST['corr_pincode'];
$perm_house = $_POST['perm_house'];
$perm_state = $_POST['perm_state'];
$perm_city = $_POST['perm_city'];
$perm_district = $_POST['perm_district'];
$perm_pincode = $_POST['perm_pincode'];
$email = $_SESSION['email'];
// $secondary_email = $_POST['secondary_email'];
$secondary_email = isset($_POST["secondary_email"]) ? $_POST["secondary_email"] : NULL;
$mobile = $_POST['mobile'];
// $alt_mobile = $_POST['alt_mobile'];
$alt_mobile = isset($_POST["alt_mobile"]) ? $_POST["alt_mobile"] : NULL;
$relative_in_csir = $_POST['relative_in_csir'];
// Prepare SQL statement with placeholders for primary_details
$sql_details = "INSERT INTO primary_details (
user_id, ssc_name, has_name_changed, new_name, mother_name, father_name, dob, age, place_ob,
citizenship, gender, religion, disability, disability_hearing,
disability_walking, disability_multiple, category, ex_servicemen,
service_years, service_months, service_days, gov_employee,
gov_organization, gov_post, csir_employee, csir_lab, csir_designation,
marital_status, staying_abroad, corr_house, corr_state, corr_city,
corr_district, corr_pincode, perm_house, perm_state, perm_city,
perm_district, perm_pincode, email, secondary_email, mobile,
alt_mobile, relative_in_csir
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)";
// Add more parameters if needed
echo "\n";
echo $_SESSION['user_id'];
echo "\n";
$user_id = $_SESSION['user_id'];
$stmt_details = $conn->prepare($sql_details);
$stmt_details->bind_param(
"issssssissssssssssiiissssssssssssissssissiis",
$user_id,
$ssc_name,
$has_name_changed,
$new_name,
$mother_name,
$father_name,
$dob,
$age,
$place_ob,
$citizenship,
$gender,
$religion,
$disability,
$disability_hearing,
$disability_walking,
$disability_multiple,
$category,
$ex_servicemen,
$service_years,
$service_months,
$service_days,
$gov_employee,
$gov_organization,
$gov_post,
$csir_employee,
$csir_lab,
$csir_designation,
$marital_status,
$staying_abroad,
$corr_house,
$corr_state,
$corr_city,
$corr_district,
$corr_pincode,
$perm_house,
$perm_state,
$perm_city,
$perm_district,
$perm_pincode,
$email,
$secondary_email,
$mobile,
$alt_mobile,
$relative_in_csir
);
if ($stmt_details->execute()) {
if (isset($_POST['relative_name']) && is_array($_POST['relative_name']) && $relative_in_csir == 'Yes') {
$stmt = $conn->prepare("INSERT INTO relatives
(user_id, relative_name, post, lab_institute, relationship)
VALUES (?, ?, ?, ?, ?)");
// Count how many relatives were submitted
$relativeCount = count($_POST['relative_name']);
// echo $relativeCount;
// echo "\n";
// echo $_POST['relative_name'][0];
// Loop through each relative entry
for ($i = 0; $i < $relativeCount; $i++) {
// Skip empty entries
if (empty($_POST['relative_name'][$i])) {
continue;
}
// Execute the prepared statement with values from this relative
$stmt->bind_param(
"issss",
$user_id,
$_POST['relative_name'][$i],
$_POST['relative_post'][$i],
$_POST['relative_lab'][$i],
$_POST['relative_relationship'][$i]
);
if ($stmt->execute()) {
} else {
echo "false1";
}
}
}
$_SESSION['primary_saved'] = "Yes";
$_SESSION['category'] = $category;
$_SESSION['disability'] = $disability;
$_SESSION['gender'] = $gender;
$_SESSION['csir_employee'] = $csir_employee;
$_SESSION['ex_servicemen'] = $ex_servicemen;
// echo "true";
header("Location: dashboard.php");
exit();
} else {
// echo "false2";
// echo "Error executing statement: " . $stmt_details->error;
header("Location: primary.php?submission=error");
}
}
$conn->close();