Jump to content

KN1V3S

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by KN1V3S

  1. Hello everyone, I'm new to PHP and I'm trying to upload a CSV-File (Table in Excel saved as CSV). The problem is that when I try to upload the file, I'm getting the error 'Notice: Undefined offset: 1 in 😄 on line 12'. Accordingly, there is a problem with the offsets 1,3,4 and 5. The error message is displayed twice. Here is my code. I'd really appreciate answers from you guys! Have a nice day! <?php $con = mysqli_connect("localhost","root","","database"); if(ISSET($_POST["import"])){ $filename = $_FILES["file"]["tmp_name"]; if($_FILES["file"]["size"] > 0){ $file = fopen($filename, "r"); while(($column = fgetcsv($file, 1000, ",")) !== FALSE){ $sqlInsert = "INSERT INTO `test1` (`id`, `firstname`, `lastname`, `gender`, `adress`) VALUES ('" . $column[0] . "', '" . $column[1] . "', '" . $column[3] . "', '" . $column[4] . "', '" . $column[5] . "' )"; $result = mysqli_query($con, $sqlInsert); if(!empty($result)){ echo "CSV Datei wurde erfolgreich in Datenbank eingetragen."; }else{ echo "Es ist ein Fehler aufgetreten."; } } } } ?> <form class ="form" action="testdoc.php" method="post" name="uploadCSV" enctype="multipart/form-data"> <div> <label>CSV Datei auswählen</label> <input type="file" name="file" accept=".csv"> <button type="submit" name="import">Import</button> </div> </form>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.