0
The following code that I present to you right below is to upload a file ". CSV" and send the data to Mysql, but the post method is not sending anything to the function . PHP, and I get the message "empty".
<!DOCTYPE html>
Upload Stock
<form action="" method="POST" enctype="multipart/form-data">
<div align="center">
<p>Upload CSV: <input type="file" name="file"></p>
<p><input type="submit" name="submit" value="Importar"></p>
</div>
</form>
<?php
include "APIConnecting.php";
if (isset($_POST["submit"])) {
if ($_FILES['file']['name']) {
$arquivo = explode(";", $_FILES['file']['name']);
if ($arquivo[1] == "csv") {
$handle = fopen($_FILES['file']['tmp_name'], "r");
while ($dados = fgetcsv($handle, 50)){
$item1 = mysqli_real_escape_string($con, $dados[0]);
$item2 = mysqli_real_escape_string($con, $dados[1]);
$sql = "INSERT INTO estoque (Chassi, Navio) VALUES ('$item1', '$item2')";
mysqli_query($con, $sql);
}
fclose($handle);
}
}
}else{echo "vazio";}
?>
How did your html? here is not working yet, is not going through the first condition. It is returning empty.
– Leandro Ramos