upload csv file in php

Solutions on MaxInterview for upload csv file in php by the best coders in the world

showing results for - "upload csv file in php"
Fritz
05 Mar 2020
1<?php
2$query = <<<eof
3    LOAD DATA INFILE '$fileName'
4     INTO TABLE tableName
5     FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
6     LINES TERMINATED BY '\n'
7     IGNORE 1 LINES
8    (field1,field2,field3,etc)
9eof;
10
11$db->query($query);
12?>
13
Fabiana
19 Aug 2017
1<?php
2// Load the database configuration file
3include_once 'dbConfig.php';
4
5// Get status message
6if(!empty($_GET['status'])){
7    switch($_GET['status']){
8        case 'succ':
9            $statusType 'alert-success';
10            $statusMsg 'Members data has been imported successfully.';
11            break;
12        case 'err':
13            $statusType 'alert-danger';
14            $statusMsg 'Some problem occurred, please try again.';
15            break;
16        case 'invalid_file':
17            $statusType 'alert-danger';
18            $statusMsg 'Please upload a valid CSV file.';
19            break;
20        default:
21            $statusType '';
22            $statusMsg '';
23    }
24}
25?>
26
27<!-- Display status message -->
28<?php if(!empty($statusMsg)){ ?>
29<div class="col-xs-12">
30    <div class="alert <?php echo $statusType; ?>"><?php echo $statusMsg; ?></div>
31</div>
32<?php } ?>
33
34<div class="row">
35    <!-- Import link -->
36    <div class="col-md-12 head">
37        <div class="float-right">
38            <a href="javascript:void(0);" class="btn btn-success" onclick="formToggle('importFrm');"><i class="plus"></i> Import</a>
39        </div>
40    </div>
41    <!-- CSV file upload form -->
42    <div class="col-md-12" id="importFrm" style="display: none;">
43        <form action="importData.php" method="post" enctype="multipart/form-data">
44            <input type="file" name="file" />
45            <input type="submit" class="btn btn-primary" name="importSubmit" value="IMPORT">
46        </form>
47    </div>
48
49    <!-- Data list table --> 
50    <table class="table table-striped table-bordered">
51        <thead class="thead-dark">
52            <tr>
53                <th>#ID</th>
54                <th>Name</th>
55                <th>Email</th>
56                <th>Phone</th>
57                <th>Status</th>
58            </tr>
59        </thead>
60        <tbody>
61        <?php
62        // Get member rows
63        $result = $db->query("SELECT * FROM members ORDER BY id DESC");
64        if($result->num_rows > 0){
65            while($row $result->fetch_assoc()){
66        ?>
67            <tr>
68                <td><?php echo $row['id']; ?></td>
69                <td><?php echo $row['name']; ?></td>
70                <td><?php echo $row['email']; ?></td>
71                <td><?php echo $row['phone']; ?></td>
72                <td><?php echo $row['status']; ?></td>
73            </tr>
74        <?php } }else?>
75            <tr><td colspan="5">No member(s) found...</td></tr>
76        <?php } ?>
77        </tbody>
78    </table>
79</div>
80
81<!-- Show/hide CSV upload form -->
82<script>
83function formToggle(ID){
84    var element = document.getElementById(ID);
85    if(element.style.display === "none"){
86        element.style.display = "block";
87    }else{
88        element.style.display = "none";
89    }
90}
91</script>
92
Melina
01 Aug 2019
1if (isset($_POST['import'])) {
2    if ($_FILES['file']['name']) {
3        $filename = explode(".", $_FILES['file']['name']);
4        if ($filename[1] == 'csv') {
5            $handle = fopen($_FILES['file']['tmp_name'], "r");
6           $i = 0;
7            while ($getData = fgetcsv($handle)) {
8                if($i > 0){
9                    $productName   = $getData[0];
10                    $productDesc   = $getData[1];
11                    $productQty   = $getData[2];
12                    $productPrice   = $getData[3];
13                    $productTotal   = $getData[4];
14                    $sql = "INSERT INTO import (productName,productDesc,productQty,productPrice,productTotal) VALUES('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "','" . $getData[4] . "')";
15                    $result = mysqli_query($conn, $sql);
16                    header("Location:import.php");
17                }
18                $i++;
19            }
20            fclose($handle);
21        }
22    }
23}
24
25Check your table name,column name & where you want to redirect using header function.
queries leading to this page
import csv file data into mysql database using phpscript import csv mysql phpphp import csv to mysqlupload csv file phpphp csv file uploadread csv and insert into database phpcsv php mysqlimport csv to mysql from htmlimport data from csv php mysql to csv database using phpphp upload and read csv filecsv imported as 3d 22 22 into database phphow to upload a csv and import it in database phpupload csv file data in database column sql query or php codeupload csv from php formimport csv into mysql phpcsv file upload in php to mysql examplecsv import phpphp and ajax code to import csv into databaseimporting csv to mysql table using phpimport csv file into mysql phpphp store data mysql loadexport data from database in csv file phpphp library to upload csv to mysqlhow to import csv file in php mysqlimport csv into mysql using php oopcsv to sql phphow to upload data to mysql in phpcsv import in phphow to upload csv file in mysql database using phpupdate mysql database through upload csv file using phpupload csv file in php exampleimport csv in mysql phpphp import data errorimport csv file in sql database with phpimport csv into mysql using phpread data from csv file and store it in database using phpread csv file and insert into database phpcsv file upload in phpupload csv file and get data in phphow to upload csv using phpimport csv data to database phpimport csv data in mysql using phpimport from csv to database 2c phpimport from csv phpupload csv file in phpimport csv data into mysql using phpcsv input into db phpimport data from scv to database phpimport csv into sql phpinport csv to database phpimport csv into sql using phpphph read from csv and connect to databseimport csv from url phpimport csv file into mysql using php demohow to upload csv file in database using phpimport csv into sql databse phpuse csv as database phpread csv insert into db phpphp mysql csv importphp csv file upload to databasescript to upload csv file to table mysqlimport data from csv and to post phpstore data through csv file php mysqlusing php to upload a csv file into databaseuploadcsv and read phpphp save csv to databasephp csv to sqlphp csv uploadphp read from csv or mysql db 3fimport csv data to mysql phpcsv file import to mysql database using phpphp csv import to mysqlhow to import comma seperate csv file to database using phpimport csv php mysqlupload and parse csv phphow to import csv file into database code phphow to export data fetched from database to csv in phpimporting csv to phphow to convert csv to database phpphp import csv file to mysqlcsv to database phphow to read csv file data in php and store in mysqlphp import data from csvcreate import csv file using phpcsv mysql phpinsert data into mysql by csv in phpphp sql csv import and saveimport a csv file in php and show in tablephp import csv data into phpphp csv to db insertimport via csv php sqlimport csv file into mysql table phpimporting csv into mysql phphow to import a file in php import data from csv to db phpget data from csv to mysql using phpuplad csv phpcsv uploading phpphp import csv to databasephp code to import email from csv to mysqlcsv file upload and print in phpupload csv file in php using query stringexport database data as csv file in phphow to import csv file save data in mysql database using phpphp import csv to sqlcsv in database phpphp csv to mysqlupdate data in csv in phpphp csv ti mysqlphp import csv into mysqluploading csv file in phpscript php import csv mysqlinsert csv into mysql using phpmysql load data infile csv phpupload file in csv format phpupload csv phpphp connect to csv databaseimport data from mysql table to csv file using phpupe data in csv in phphow to create csv file from data from database in phpphp read from csv file to dbimport csv file int databaseusing php scriptphp sql csv importphp upload csv file to mysqlwrite database query csv file in phpupload csv file safely in phpuse csv file as database phpcsv upload query in phpphp save data from csv to dbhtml to import csv to mysqlimport data from csv in phpimport csv to mysql in phpupload and import csv phpphp export mysql data to csv file functionhow to upload csv file with php into dbphp upload csv to dbupload csv to php mysqlcsv upload in phpimport data from csv in sql phpupload csv to database phpimport data using csv in phpphp sql csv import dbalupload csv file in database using phphow to get csv to database phpupload csv using phpphp csv to databasephp upload csvphp upload content of csv to mysqlimport csv to mysql phphow to import from a csv file in phpread csv file and insert into database in phpimport csv in database phpphp csv to mysql importupload csv in database phphow to export data from database to csv file in phpcreate a db table where we can import the csv file in phpphp upload csv to mysqlread csv file in php and store into mysqlhow to read csv file into mysql database in phphow to import csv to mysql phpimport csv file into sql server using phpimport from csv to sql with phpcsv file to database phpupload csv data to database phpphp examples of an csv importerupload csv file data in database column sql query for php codeupload csv file in database using query string in phpimport csv to mysql in php without using load data infileimport csv file into database mysql phphow to get data from csv file using php and store it into mysql databasephp use csv as databasephp import csv file to mysql tablephp mysql csv import dbalimport from csv to sql with php and save imagephp imported file geting 3f 3f 3f to view using tablehow to read csv file in php and store in mysqlphp product import through csv and save to mysqlupload csv and read phpread csv file and store the data in sql database phpphp cvs uploadphp csv from databasehow to import php mysql data to csv through phpimport csv in php mysqlhow to import csv file to mysql database using phpimport csv into mysql database with phpphp mysql bulk insert csvhow to handle csv file with php read write import export with databasecsv image upload phpimport csv file in phpcsv upload phpupload csv to mysql phphow to upload csv file in phpupload csv file to phpmyadmin dynamicallyupload csv file in php