Import CSV to MySQL using PHP | Display Imported Data

Import CSV to MySQL using PHP | Display Imported Data

CodeFlix

4 года назад

29,102 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

リープ
リープ - 04.06.2023 20:09

It was a great video. I learned a lot.

Ответить
OPBR Clips
OPBR Clips - 12.02.2023 07:08

where's the code for the button choose file?

Ответить
Wanderson Gomes
Wanderson Gomes - 23.10.2022 06:19

Muitissimo obrigado. Era exatamente isto que eu estava procurando. Valeu irmão.

Ответить
Yogeswaran Yogakrishanthi
Yogeswaran Yogakrishanthi - 05.05.2022 17:41

i got an error as Undefined index: file

Ответить
Sheren Regina Pingkan
Sheren Regina Pingkan - 21.04.2022 17:47

how about the csv file size is 60 mb and has 60k rows? Which code should be changed?

Ответить
Suleman Mughal
Suleman Mughal - 14.03.2022 20:13

is there anyway that column automatically adjust to the csv file in the database while uploading

Ответить
Nilesh Mankar
Nilesh Mankar - 30.12.2021 23:05

if(isset($_POST["import"])){
$filename = $_FILES["file"]["tmp_name"];

if($_FILES["file"]["size"]>0){
$file = fopen($filename,"r");

while (($column) = fgetcsv ($file, 10000, ",")) !== FALSE) {
$sqlinsert = "insert into data (name,type) values ('".$column[0]."','".$column[1]."')";

$result = mysqli_query($conn,$sqlinsert);

if (!empty($result)) {
echo "csv imported";
}else{
echo "problem";
}
}
}
} ------- line 12 errr ??--

Ответить
Aaron Esteban
Aaron Esteban - 28.12.2021 00:25

AWESOME! IT WORKED! THANK YOU SO MUCH!

Ответить
Angga Candra
Angga Candra - 17.07.2021 15:42

can u drop the csv file structure?

Ответить
Vidyashree H s
Vidyashree H s - 20.06.2021 03:43

problem: Undefined array key "file"

Warning: Trying to access array offset on value of type null line 6

Ответить
Will
Will - 25.04.2021 01:10

This is my code, i dont even get an error, nothing happens please help, my csv file was created with notepadd ++ and have 3 columns of string
<?php

$conn=mysqli_connect("localhost","root","","csv");


if(isset($_POST["import"])){

$fileName=$_FILES["file"]["tmp_name"];

if($_FILES["file"]["size"]>0){
$file = fopen($filename,"r");

while(($column=fgetcsv($file,1000,","))!==FALSE)
{
$sqlInsert="Insert into data(name,type,email) values('".$column[0]."', '".$column[1]."', '".$column[2]."')";

$result=mysqli_query($conn,$sqlInsert);

if(!empty($result)){
echo "CSV data imported into database";
}
else{
echo "Problem in importing csv";
}
}

}
}



?>

<form class="form-horizoontal" action="" method="post" name="uploadCsv" enctype="multipart/form-data">

<div>
<label>Chose a csv file</label>
<input type="file" name="file" accept=".csv">
<button type="submit" name="Submit">Import</button>

</div>

</form>

Ответить
Edwin Sanchez
Edwin Sanchez - 17.04.2021 18:14

Muy fácil, espero me salga igual.

Ответить
Andrew Otieno
Andrew Otieno - 16.04.2021 14:29

which code editor are you using? I've been using notepad++ which seems to lack some features.

Ответить
Bhavik Sumera
Bhavik Sumera - 28.03.2021 11:37

Problem : Only 0th row i'm getting in array but other rows are missing...

Ответить
MUGIWARA
MUGIWARA - 04.03.2021 17:21

I try to copy all codes but didn't work on my scratch, always echoing "Problem in importing csv"

Ответить
Fadoua Bouchtat
Fadoua Bouchtat - 20.02.2021 14:03

Can i get the code please

Ответить
Photamora_planet
Photamora_planet - 09.02.2021 13:43

Sir....I have got error
This while loop is not getting terminated

Ответить
Dan Vallesfin
Dan Vallesfin - 18.01.2021 04:31

Hi CodeFlix - I've got this error "Warning: Undefined array key "temp_name". May I know where is this "temp_name"

Ответить
Abegail Grace Ulanday
Abegail Grace Ulanday - 07.11.2020 19:19

does your CSV file contains the table column names?

Ответить
Amir Khan
Amir Khan - 29.10.2020 06:13

can I get this code?

Ответить
zqw
zqw - 09.09.2020 19:59

i hope you react soon bro

Ответить
zqw
zqw - 09.09.2020 19:58

2.51 what did you do there on line 13? with that comma
because i have a error: Parse error: syntax error, unexpected ';'

otherwise you can comment the code on line 13 below thnx!

Ответить
Happy Arif
Happy Arif - 30.06.2020 06:43

awesome tuts :). Keep it up bro

Ответить
j328
j328 - 29.06.2020 08:47

The code was working on my users table but not on the other. I don't know why. I tried to echo the $sqlInsert and run to phyMyAdmin it works but not in the php code.

Ответить