KN1V3S
Members-
Posts
26 -
Joined
-
Last visited
KN1V3S's Achievements
Member (2/5)
0
Reputation
-
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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 "..." 😅 -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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! -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
KNr. is the name of the column in the db -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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> -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
-
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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! -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
Is there a fast method of checking that? -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
I dont understand your question -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
-
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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 -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
This is my table's structure (I'm still a beginner at working with databases so if there are major mistakes, please tell me!) -
PHP CSV Upload - Some rows in CSV file aren't in database
KN1V3S replied to KN1V3S's topic in PHP Coding Help
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. -
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."; } } ?>
-
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
-
Thank you all for your help guys, I really appreciate you taking your time for my problem. Have a nice day!