I have written a code upload multiple CSV files using PHP; which has been working quite well. However, I just discovered that this code would not work for a particular CSV file. This file has some null values as data, which we intend to update later on. I have debugged multiple times, but no luck. I could read the contents (headers and data) of the CSV file, but they are not being written into the database.
The error I’m seeing is: Invalid parameter number: number of bound variables does not match number of tokens in
Here is a snippet of the my code:
for ($i = 0;$i < $file_count;$i++){
$file_name = $_FILES["file-$i"]['name'];
$file_type = $_FILES["file-$i"]['type'];
$file_tmp_name = $_FILES["file-$i"]['tmp_name'];
$file_error = $_FILES["file-$i"]['error'];
$file_size = $_FILES["file-$i"]['size'];
$handle = fopen($_FILES["file-$i"]['tmp_name'], "r");
$headers = fgetcsv($handle, 1000, ",");
//print_r($headers) . "<br>";
$table_name = create_table($file_name, $headers);
$csv_data = [];
while (($data = fgetcsv($handle, 1000, ",")) !== false){
//print_r($data) . "<br>";
array_push($csv_data, $data);
}
//print_r($csv_data);
fclose($handle);
//echo "===================================================================================================================================" . "<br>";
//insert records to table
echo insert_records($table_name, $headers, $csv_data);
}
function create_table($file_name, $csv_headers){