This question has probably been asked millions of times but I don't know why I can't find a code that works for me. I'm assigned this task to write a quite complex script to populate the database with an excel CSV (should accept both formats) spreadsheet. All I'm trying now is to see if I can even read the file Properly (before doing any manipulation/parsing). Below is what I have, can someone help to to have a basic working script for such a simple example?
PHP
<?php include 'connection.php';?>
<?php
if(isset($_POST["search"]))
{
$file = $_FILES['file_save']['tmp_name'];
$handle = fopen($file, "r");
while(($filesop = fgetcsv($handle, ",")) !== false)
{
$name = $filesop[0];
$email = $filesop[1];
$query = mysqli_query("INSERT INTO $dbname.CSV (fname, lname) VALUES ('$name','$email')");
$result = mysqli_query($conn,$query);
echo $query;
}
}
?>
HTML
<form method="post" action="#">
Market Share:<br>
<input type="file" name="file_save">
<button style="" type="submit" class="btn btn-default" name="search">Save</button>
</form>
<?php include 'save_import.php';?>