I add a file in the form and I need to insert the data into the database, I’m doing everything right, but I’m not receiving an error or updating the database. Here is the script
<section> <header style="text-align: center; padding: 0 0 30px 0; font-size: 1.5em"> Выберите файл для импорта </header> <form method="post" action="" enctype="multipart/form-data" style="text-align: center"> <label> <p style="text-align: justify; padding: 0 0 0 470px"> Выбранный файл <input type="file" name="file" /> </p> </label> <label> <p style="text-align: justify; padding: 0 0 0 470px"> Загрузить <input type="submit" name="submit" /> </p> </label> </form> </section> <?php // setting session $session_start = session_start(); $session_id = session_id(); //setting connect DB $dsn = 'mysql:host=localhost;dbname=ListGood'; $username = 'root'; $password = 'nemate666'; // connect DB $dbh = new PDO($dsn, $username, $password); // count orders $count_orders = $dbh->query('SELECT COUNT(*) FROM Product')->fetchColumn(); // work with csv if($_POST['submit'] && $_FILES['file']['size'] > 0) { $filename = $_FILES['file']['tmp_name']; $file = fopen($filename, 'r'); try { $statement_insert = $dbh->prepare( 'INSERT INTO Product(id, name, name_trans, price, small_text, big_text, user_id) VALUES(?, ?, ?, ?, ?, ?, ?)'); if ($count_orders == 0) { while (($getData = fgetcsv($file, 1000, ",")) !== FALSE) { $statement_insert->execute([$getData[0], $getData[1], $getData[2], $getData[3], $getData[4], $getData[5], $session_id] ); } fclose($file); } else { echo 'dfgfg'; } } catch(PDOException $e) { echo $e->getMessage(); } } And a piece of CSV file
1,Samsung,"Samsung galaxy",10.1,"Сайт рыбатекст","Сайт рыбатекст поможет дизайнеру, верстальщику, вебмастеру сгенерировать несколько абзацев более менее осмысленного текста рыбы на русском языке, а начинающему оратору отточить навык публичных выступлений в домашних условиях"