true, 'file_name' => $fileName]; } else { return ['status' => false, 'message' => 'Error in file uploading.']; } } // Get selected state from POST (when form submits) or from database (when page loads) $selected_state_id = isset($_POST['state_id']) ? $_POST['state_id'] : ''; if (isset($_POST['status']) && $_POST['status'] == 'insert') { $imgUploadResult = []; if (!empty($_FILES['image']['name'])) { $imgUploadResult = uploadFile('image', '../uploads/centers/'); if (!$imgUploadResult['status']) { echo ''; exit; } } $query = "UPDATE `centers` SET `center_number` = '" . $_POST['center_number'] . "', `name` = '" . $_POST['name'] . "', `institute_name` = '" . $_POST['institute_name'] . "', `dob` = '" . $_POST['dob'] . "', `pan_number` = '" . $_POST['pan_number'] . "', `aadhar_number` = '" . $_POST['aadhar_number'] . "', `center_full_address` = '" . $_POST['center_full_address'] . "', `state_id` = '" . $_POST['state_id'] . "', `city_id` = '" . $_POST['city_id'] . "', `no_of_computer_operator` = '" . $_POST['no_of_computer_operator'] . "', `no_of_class_room` = '" . $_POST['no_of_class_room'] . "', `total_computer` = '" . $_POST['total_computer'] . "', `space_of_computer_center` = '" . $_POST['space_of_computer_center'] . "', `whatsapp_number` = '" . $_POST['whatsapp_number'] . "', `contact_number` = '" . $_POST['contact_number'] . "', `email_id` = '" . $_POST['email_id'] . "', `qualification_of_center_head` = '" . $_POST['qualification_of_center_head'] . "', `staff_room` = '" . $_POST['staff_room'] . "', `water_supply` = '" . $_POST['water_supply'] . "', `toilet` = '" . $_POST['toilet'] . "', `reception` = '" . $_POST['reception'] . "', `username` = '" . $_POST['username'] . "', `password` = '" . $_POST['password'] . "', `issue_date` = '" . $_POST['issue_date'] . "', `valid_upto` = '" . $_POST['valid_upto'] . "'"; if (!empty($_FILES['image']['name'])) { $query .= ", `image` = '" . $imgUploadResult['file_name'] . "'"; // Delete old image file if (file_exists("../uploads/centers/" . $_POST['old_image'])) { unlink("../uploads/centers/" . $_POST['old_image']); } } $query .= " WHERE `id` = '" . $_GET['id'] . "'"; $result = $con->query($query); if (!$result) { die('Error: ' . $con->error); } echo ''; exit; } // Fetch center data $get = $con->query("SELECT * FROM centers where id = '" . $_GET['id'] . "'")->fetch_assoc(); // If no selected state from POST, use the one from database if (empty($selected_state_id)) { $selected_state_id = $get['state_id']; } // Fetch all cities for the selected state $cities = []; if (!empty($selected_state_id)) { $city_query = $con->query("SELECT * FROM city WHERE state_id = '$selected_state_id' ORDER BY city_name ASC"); if ($city_query && $city_query->num_rows > 0) { while ($c = $city_query->fetch_assoc()) { $cities[] = $c; } } } else { // Fallback: show all cities if no state selected $city_query = $con->query("SELECT * FROM city ORDER BY city_name ASC"); if ($city_query && $city_query->num_rows > 0) { while ($c = $city_query->fetch_assoc()) { $cities[] = $c; } } } ?>

Franchisee Form