connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// File upload handling
if (isset($_FILES['excelFile'])) {
$file = $_FILES['excelFile']['tmp_name'];
$category = $_POST['textdate'];
echo $category;
// Load the spreadsheet
$spreadsheet = IOFactory::load($file);
$sheetNames = $spreadsheet->getSheetNames(); // Get all sheet names
// Prepare the SQL statement
// Loop through each sheet
foreach ($sheetNames as $index => $sheetName) {
$sheet = $spreadsheet->getSheet($index);
$rows = $sheet->toArray();
echo "Sheet Name: " . $sheetName . "
";
// Skip the first row (header)
array_shift($rows);
// print_r($rows); // or use var_dump($rows);
$r = 0; // Initialize row counter
$pd=1;
$sql="insert into worker_master (eb_id,eb_fixed_id,active,eb_no,emp_code,worker_name,middle_name,last_name,company_id,dept_id,cata_id,desg_id,branch_id,date_of_joining)
select thepd.eb_id,thepd.eb_id fxid,'Y' act,theod.emp_code eb_no,theod.emp_code emp_code,
thepd.first_name,thepd.middle_name,thepd.last_name,
company_id,theod.department_id,theod.catagory_id,theod.designation_id,theod.branch_id,date_of_join
from tbl_hrms_ed_personal_details thepd
LEFT join (select * from tbl_hrms_ed_official_details theod where is_active=1) theod
on thepd.eb_id =theod.eb_id
where theod.emp_code ='";
// Insert data row by row
foreach ($rows as $row) {
$eb= isset($row[0]) ? $row[0] : '';
$ebid=0;
$sql="select eb_id from worker_master where eb_no='".$eb."'";
echo $sql."";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
$ebid=$row["eb_id"];
}
if ($ebid==0) {
$sql="insert into worker_master (eb_id,eb_fixed_id,active,eb_no,emp_code,worker_name,middle_name,last_name,company_id,dept_id,cata_id,desg_id,branch_id,date_of_joining)
select thepd.eb_id,thepd.eb_id fxid,'Y' act,theod.emp_code eb_no,theod.emp_code emp_code,
thepd.first_name,thepd.middle_name,thepd.last_name,
company_id,theod.department_id,theod.catagory_id,theod.designation_id,theod.branch_id,date_of_join
from tbl_hrms_ed_personal_details thepd
LEFT join (select * from tbl_hrms_ed_official_details theod where is_active=1) theod
on thepd.eb_id =theod.eb_id
where theod.emp_code ='";
$eb= isset($row[0]) ? $row[0] : '';
$sql=$sql.$eb."'";
echo $sql;
if (strlen($eb)>2) {
$conn->query($sql);
}
}
}
$r++; // Correct increment
}
}
echo "Data imported successfully!";
$conn->close();
echo "";
?>