Horje
upload csv file in php Code Example
import data from csv to db php
<?php
$query = <<<eof
    LOAD DATA INFILE '$fileName'
     INTO TABLE tableName
     FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
     LINES TERMINATED BY '\n'
     IGNORE 1 LINES
    (field1,field2,field3,etc)
eof;

$db->query($query);
?>
upload csv file in php
if (isset($_POST['import'])) {
    if ($_FILES['file']['name']) {
        $filename = explode(".", $_FILES['file']['name']);
        if ($filename[1] == 'csv') {
            $handle = fopen($_FILES['file']['tmp_name'], "r");
           $i = 0;
            while ($getData = fgetcsv($handle)) {
                if($i > 0){
                    $productName   = $getData[0];
                    $productDesc   = $getData[1];
                    $productQty   = $getData[2];
                    $productPrice   = $getData[3];
                    $productTotal   = $getData[4];
                    $sql = "INSERT INTO import (productName,productDesc,productQty,productPrice,productTotal) VALUES('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "','" . $getData[4] . "')";
                    $result = mysqli_query($conn, $sql);
                    header("Location:import.php");
                }
                $i++;
            }
            fclose($handle);
        }
    }
}

Check your table name,column name & where you want to redirect using header function.




Php

Related
how to select and deselect all items without use name in laravel Code Example how to select and deselect all items without use name in laravel Code Example
php remove new line character from string Code Example php remove new line character from string Code Example
convert float to integer laravel Code Example convert float to integer laravel Code Example
laravel project preparation,laravel project create Code Example laravel project preparation,laravel project create Code Example
csrf token mismatch laravel api Code Example csrf token mismatch laravel api Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7