PHP CSV Upload – Some rows in CSV file aren't in database

  Uncategorized

Hello everyone,

as described above, whenever I upload a CSV doc with more than 600 rows of data, some of those rows went missing.
I thought it was maybe the format of the data itself, but that was not the case. I couldn’t identify the problem.
Unfortunately I can’t share the CSV file since it contains sensitive information.
I need help with writing a specific PHP code that tells me which row of the CSV file couldn’t be uploaded into the database.
My current php code is below.

Let me know if you need more information.

Kind regards

Knives

<?PHP
$con = mysqli_connect(“localhost”, “root”, “”,”csvupload”);

if(ISSET($_POST[‘import’]))
{
$filename = $_FILES[“file”][“tmp_name”];

if(ISSET($_POST[‘checkbox’]))
{
$skipRow = 0;
}
else
{
$skipRow = 1;
}
if($_FILES[“file”][“size”] > 0);
{
$file = fopen($filename, “r”);

}
while(($column = fgetcsv($file, 10000, “;”)) !== FALSE)
{
$skipRow++;
if ($skipRow == 1) { continue; }
$sqlInsert = “INSERT INTO `adressen_neu` (`KNr.`, `Anrede`, `Vorname`, `Name`, `Name2`, `Name3`, `Land`, `PLZ`, `Ort`, `Strasse`, `Telefon`, `Telefax`, `Email`) VALUES (‘$column[0]’, ‘$column[1]’, ‘$column[2]’, ‘$column[3]’, ‘$column[4]’, ‘$column[5]’, ‘$column[6]’, ‘$column[7]’, ‘$column[8]’, ‘$column[9]’, ‘$column[10]’, ‘$column[11]’, ‘$column[12]’)”;
$result = mysqli_query($con, $sqlInsert);

}
if(!empty($result))
{
echo “Ein Fehler ist aufgetreten.”;
}
else
{
echo “Erfolgreich in die Datenbank eingetragen.”;
}
}
?>

 

Source: ASK PHP QUESTIONS

LEAVE A COMMENT