Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by KN1V3S

  1. True, I've heard about prepared queries but as I said, I really am a beginner and don't have the know-how yet. But I will look into that! Thank you Oh and I meant '...' not "..." 😅
  2. Thanks for the advice. I've been able to find out which Arrays haven't been registered into the database. It turned out, every Array with '' in them couldn't be uploaded. The reason was sql query. It couldn't handle these characters since they were already implemented in the code. That's why I've turned the arrays into real escape strings with "mysqli_real_escape_string()". Now everything is working flawlessy. Thanks for your help!
  3. I'm really sorry for bothering you so much, but now I'm getting this error: Fatal error: Uncaught Error: Call to a member function fetch_row() on bool in C:\xampp\htdocs\array_comparison.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\array_comparison.php on line 19 <?php $con = mysqli_connect("localhost", "root", "","csvupload"); if(ISSET($_POST['import'])) { $filename = $_FILES["file"]["tmp_name"]; $array1 = []; $array2 = []; $file = fopen($filename, "r"); while (($column = fgetcsv($file, 10000, ";")) !== FALSE) { $array1[] = $column[0]; } $res = $con->query("SELECT KNr. FROM adressen_neu"); while ($row = $res->fetch_row() ) { $array2[] = $row[0]; } echo '<pre>' . print_r(array_diff($array1, $array2), 1) . '</pre>'; } ?> <!DOCTYPE html> <html> <head> <title>CSV Upload-Page</title> </head> <body> <form class="form" name="uploadCSV" action="array_comparison.php" method="post" enctype="multipart/form-data"> <div> <label>Select CSV File</label> <input type="file" name="file" accept=".csv"> <button type="submit" name="import">Import</button> <input type="checkbox" name="checkbox" value="checked"> </div> </form> </body> </html>
  4. I know it looks silly, but I implemented "var_dump(count($column) < 1);" to check if there are some arrays that have a value of 0. But it turned out that there was not a single array that had the value 0. Doesn't that mean that there might be issues from the db? Correct me if I'm wrong!
  5. This is the output from SHOW CREATE TABLE adressen_neu
  6. Hi Phill, thanks for your suggestion, could you please tell me how I can copy all the entries of the database into a worksheet? Kind regards, Knives
  7. This is my table's structure (I'm still a beginner at working with databases so if there are major mistakes, please tell me!)
  8. That's what I'm currently trying to find out. But since there are 623 lines, it's a bit difficult to see which ones are missing. I compared the amount of rows in the database and in the original CSV file. In the original CSV file, there are 623 rows of data. In the database, there are 613 entries. That means that 10 rows are gone. Unfortunately I can't find out which ones are not being added into the db.
  9. 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."; } } ?>
  10. Hello everyone, I have a small problem here. I want to create a basic 'searchengine' for my database. Which means: people give an input X for example and this function searches every entry in the database for that input X and shows it in a table to the user. So far, it's showing me every current entry in the database, which is what I wanted. But the problem is, that whenever I make an input for the search, nothing happens. It's as if the page didn't change at all. I took a look earlier in my variables, but I couldn't find anything. Heres my source code. You can also find it in the attachment. <?php if(ISSET($_POST['search'])){ $valueToSearch = $_POST['suchfilter']; $query = "SELECT * FROM `tabelle` WHERE CONCAT(`firstname`, `lastname`, `gender`, `adress`) LIKE'%".$valueToSearch."%'"; $search_result = filterTable($query); } else { $query = "SELECT * FROM `tabelle`"; $search_result = filterTable($query); } function filterTable($query){ $con = mysqli_connect("localhost","root","","csvtest"); $filt_result = mysqli_query($con, $query); return $filt_result; echo $filterTable; } ?> <!DOCTYPE html> <html> <head> <title>Suchfilter</title> </head> <body> <form> <input type="text" name="suchfilter" placeholder="suchwert"><br><br> <input type="submit" name="search" value="Filter"><br><br> <table> <tr> <th>firstname</th> <th>lastname</th> <th>gender</th> <th>adress</th> </tr> <?php while($row = mysqli_fetch_array($search_result)):?> <tr> <td><?php echo $row['firstname'];?></td> <td><?php echo $row['lastname'];?></td> <td><?php echo $row['gender'];?></td> <td><?php echo $row['adress'];?></td> </tr> <?php endwhile;?> </table> </form> </body> </html> I'd appreciate an answer since this is something really important to me. Best regards Knives source.txt
  11. Thank you all for your help guys, I really appreciate you taking your time for my problem. Have a nice day!
  12. I believe you meant that with your reply, sorry for not understanding it. I've fixed it now!
  13. Oh god thanks xD Now I feel really stupid for not noticing that.
  14. Hey Barand, this is the new code. <?php $con = mysqli_connect("localhost","root","","csvtest"); if(ISSET($_POST["import"])){ $filename = $_FILES["file"]["tmp_name"]; if($_FILES["file"]["size"] > 0){ $file = fopen($filename, "r"); while(($column = fgetcsv($file, 10000, ";")) !== FALSE){ var_dump($column); $sqlInsert = "INSERT INTO `test1` (`id`, `firstname`, `lastname`, `gender`, `adress`) VALUES ('$column[0]', '$column[1]', '$column[2]', '$column[3]')"; $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>
  15. Hi Barand, yes I've seen your reply. I fixed it, I adjusted the query command to have only 4 columns. It still won't work.
  16. Could you maybe take a look into my csv files? I think they're the issue here.
  17. So I reviewed everything, I adjusted my query part but it still wouldnt work. The only thing I might be thinking is that my CSV formatting is wrong but I'm not sure.
  18. Thank you all for your replies, I‘ll take a look into them later when I‘m home! I really appreciate your help guys :)
  19. At the moment I'm not getting the 'Undefined offset' error anymore, but now it seems like it just wouldn't upload the arrays of the csv into my database.
  20. I've added 'var_dump($column);' just to see the array printed out. This is what it looks like with the csv file. I'm clueless, I really don't know how to solve this issue.
  21. This is what my CSV file looks like in Excel
  • 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.