Data not inserting into the database table. but when var_dump it show all record to be inserted

that is the headings we are using already.
am more concern on the if condition inside the for loop

The conditions are checking each $v which are values of the fields array. So when making comparison checks they are to values of the fields array.

don’t still get you pls. pls come with code sample

	$highestRowIndex = $worksheet->getHighestRow();
	$highestColumnIndex = $worksheet->getHighestColumn();
	
	for ($row = 1; $row <= $highestRowIndex; $row++) { 
	
		$headings = $worksheet->rangeToArray('A1:' . $highestColumnIndex . 1,null, true, false);
		array_walk($headings[0], function(&$value)
		{
		 // $value = str_replace(" ", "" ,strtolower($value));  
		  $value = preg_replace("/[^a-zA-Z]+/", "",strtolower($value)); 
		});
			
		
		
		$rowData = $worksheet->rangeToArray('A' . $row . ':' . $highestColumnIndex . $row, null, true, false);

		$fields = array(
		  'title'
		, 'surname'
		, 'firstname'
		, 'middlename'
		, 'gender'
		, 'dob'
		, 'maritalstatus'
		, 'occupation'
		, 'phonenumber'
		, 'companyname'
		, 'registrationtype'
		, 'registeredby'
		, 'taxid'
		, 'officeaddress'
		, 'officecity'
		, 'tempreg'
		, 'workplacecategory'
		, 'active'
		, 'monthlygross'
		, 'NHF'
		, 'NHIS'
		, 'NSITF'
		, 'basicsalary'
		, 'grade'
		, 'designation'
		, 'pension'
		, 'gratuity'
		); 
		$first_names = array();		
		$matches = array_intersect($headings[0],$fields);	

		$values = array();
		foreach($fields as $k => $v):
			if($v == "occupation"){
				$values[] = $textfile_occupation;
			}elseif($v == "companyname"){
				$values[] = $institution;
			}elseif($v == "registeredby"){
				$values[] = $UserLogin;
			}else{
				$values[] = (in_array($v,$matches) ? $rowData[0][array_search($v,$matches)] : '');
			}		
		endforeach;
		
		$row_values = implode(',',$values);	
		
		echo "<pre>";
		print_r($values);	
		echo "</pre>";
		//$stmt =$connect->prepare("INSERT INTO tem_treg2 (title,surname,first_name,middle_name,gender,dob,marital_status,occupation,phone_number,company_name,registration_type,registered_by,tax_id,office_address,office_city,temp_reg,workplace_category,active,monthly_gross,nhf,nhis,nsitf,basic_salary,grade,designation,pension,gratuity) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		//$stmt->bind_param("sssssssssssssssssssssssssss",$row_values);
		//$stmt->execute();
	}

this is what we had at #50

this is the result i got.
when echo “

”;
print_r($values);
echo “
”;

Array
(
[0] => ACCOUNTANT - CHARTERED
[1] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[2] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[3] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[4] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[5] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[6] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[7] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[8] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[9] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[10] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[11] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[12] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
[21] =>
[22] =>
[23] =>
[24] =>
[25] =>
[26] =>
)

Maybe you should POST what YOU are using and explain what the problem is.

this is what i did expecting varaible to assign to $values when the headding match. but how to handle that is what am asking now becoause the one i have read in a static way. pls help with code sample

if($v == "title"){
				$values[] = $textfile_occupation;
			}elseif($v == "surname"){
				$values[] = '';
			}elseif($v == "first_name"){
				$values[] = '';
			}
			elseif($v == "middle_name"){
				$values[] = '';
			}
			elseif($v == "gender"){
				$values[] = '';
			}
			elseif($v == "name's"){
				$values[] = '';
			}
			elseif($v == "fullname"){
				$values[] = '';
			}
			elseif($v == "dob"){
				$values[] = '';
			}
			elseif($v == "marital_status"){
				$values[] = '';
			}
			elseif($v == "occupation"){
				$values[] = '';
			}
			elseif($v == "phone_number"){
				$values[] = '';
			}
			elseif($v == "company_name"){
				$values[] = $institution;
			}
			elseif($v == "registration_type"){
				$values[] = '';
			}
			elseif($v == "registered_by"){
				$values[] = $UserLogin;
			}
			elseif($v == "tax_id"){
				$values[] = '';
			}
			elseif($v == "office_address"){
				$values[] = '';
			}
			elseif($v == "office_city"){
				$values[] = '';
			}
			elseif($v == "temp_reg"){
				$values[] = '';
			}
			elseif($v == "workplace_category"){
				$values[] = '';
			}
			elseif($v == "active"){
				$values[] = '';
			}
			elseif($v == "monthly_gross"){
				$values[] = '';
			}
			elseif($v == "NHF"){
				$values[] = '';
			}
			elseif($v == "NHIS"){
				$values[] = '';
			}elseif($v == "NSITF"){
				$values[] = '';
			}elseif($v == "basic_salary"){
				$values[] = '';
			}elseif($v == "grade"){
				$values[] = '';
			}elseif($v == "designation"){
				$values[] = '';
			}elseif($v == "pension"){
				$values[] = '';
			}

and here is the result

Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] => DIAMOND BANK PLC (ABAKALIKI, OGOJA RD)
[10] =>
[11] => ezejonah
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
[21] =>
[22] =>
[23] =>
[24] =>
[25] =>
[26] =>
)

What code are you using?
Didn’t at one point you had all records being added to values array but some values were missing?

my old code that am runing away from.
here is it
//$pension = $columnNames = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(17, $row)->getValue());
//$gratuity = $columnNames = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(18, $row)->getValue());

and i hate this code with everything in me because it’s not given me what i want. pls help me with sample code i really believe that you have a solution to this

How are using the PARTS of code I provide within what you already have?

i mean the code i was using.

i can’t implement this frusytrating code into a solution. am not using with the one you provided.

Well this is complete code I am using for testing.

/*
TEST PAGE SAMPLE
This is only a partial sample that does not have FORM or other parts assumed to be used.
Will Need to edited to meet your needs.
*/	

//Define path to PHPExcel 
include '../PHPExcel/IOFactory.php';

if(isset($_POST['surname'])): 

	//Define path to Excel file
	$inputFileName = '';

	try {
		$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
		$objReader = PHPExcel_IOFactory::createReader($inputFileType);
		$objPHPExcel = $objReader->load($inputFileName);
	} catch (Exception $e) {
		die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . 
		$e->getMessage());
	}
	
	$worksheet = $objPHPExcel->getSheet(0);  

  		
	//THESE POST values should be checked before proceeding
	$institution=$_SESSION['Company'];
	$UserLogin=$_SESSION['UserLogin'];
	$textfile_surname = $_POST['surname'];
	$textfile_occupation = $_POST['occupation2'];
	$textfile_occupation1 = $_POST['occupation'];
	$textfile__monthlygross = $_POST['monthly_gross']; 
	
	$fields = array(
	  'title' 
	, 'surname'
	, 'firstname'
	, 'middlename'
	, 'gender'
	, 'dob'
	, 'maritalstatus'
	, 'occupation'
	, 'phonenumber'
	, 'companyname'
	, 'registrationtype'
	, 'registeredby'
	, 'taxid'
	, 'officeaddress'
	, 'officecity'
	, 'tempreg'
	, 'workplacecategory'
	, 'active'
	, 'monthlygross'
	, 'NHF'
	, 'NHIS'
	, 'NSITF'
	, 'basicsalary'
	, 'grade'
	, 'designation'
	, 'pension'
	, 'gratuity'
	); 
	
	$highestRowIndex = $worksheet->getHighestRow();
	$highestColumnIndex = $worksheet->getHighestColumn();
	
	for ($row = 1; $row <= $highestRowIndex; $row++) { 
	
		$headings = $worksheet->rangeToArray('A1:' . $highestColumnIndex . 1,null, true, false);
		array_walk($headings[0], function(&$value)
		{ 
		  $value = preg_replace("/[^a-zA-Z]+/", "",strtolower($value)); 
		});
			
		
		
		$rowData = $worksheet->rangeToArray('A' . $row . ':' . $highestColumnIndex . $row, null, true, false);

			
		$matches = array_intersect($headings[0],$fields);	

		$values = array();
		foreach($fields as $k => $v):
			if($v == "occupation"){
				$values[] = $textfile_occupation;
			}elseif($v == "companyname"){
				$values[] = $institution;
			}elseif($v == "registeredby"){
				$values[] = $UserLogin;
			}else{
				$values[] = (in_array($v,$matches) ? $rowData[0][array_search($v,$matches)] : '');
			}		
		endforeach;
		
		$row_values = implode(',',$values);	
		
		echo "<pre>";
		print_r($values);	
		echo "</pre>";
		//$stmt =$connect->prepare("INSERT INTO tem_treg2 (title,surname,first_name,middle_name,gender,dob,marital_status,occupation,phone_number,company_name,registration_type,registered_by,tax_id,office_address,office_city,temp_reg,workplace_category,active,monthly_gross,nhf,nhis,nsitf,basic_salary,grade,designation,pension,gratuity) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		//$stmt->bind_param("sssssssssssssssssssssssssss",$row_values);
		//$stmt->execute();
	} 

endif;

ok i should edit

if(isset($_POST[‘surname’])):

//Define path to Excel file
$inputFileName = '';

try {
	$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
	$objReader = PHPExcel_IOFactory::createReader($inputFileType);
	$objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
	die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . 
	$e->getMessage());
} 

to meet my needs as per the xls heading data?.

Use the page you already have. This is just a sample of what I have. It’s the section on defining the fields array and matching results (the part we have seem over and over again) that you would use. Not the opening of the file or any of that or the FOR loop where I am looping through rows as your code already had that right?

ok. i should use the dropdown file with it name according to the xls file heading to checkmate it after checking if the field issset

You’re loosing me man…
Feels like this is going backwards.
Didn’t at one point say you had all the file read?

yes, should i use the read i did before. that is the sample i gave you above and i told you that it read in a static manner. that is why/what am asking.

you are not getting me.

i read the file in a static manner.
we are almost done. pls help me out ok

OK but we seem to be getting nowhere.

  1. If you print_r the headings array are the values letters only lowercase?

  2. Do the headings match what you have in the fields array?