Judul : PHP CODE EXAMPLE FOR IMPORTING CSV FILES
link : PHP CODE EXAMPLE FOR IMPORTING CSV FILES
PHP CODE EXAMPLE FOR IMPORTING CSV FILES
STEP 1:
create table myrecord
(id int primary key auto_increment,
name varchar(200),
city varchar(200)
);
STEP 2 :now write code for import.php file:
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "t";
$conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
mysql_select_db("$database", $conn) or die(mysql_error());
?>
<html>
<body>
<div >Import Excelsheet Data in mysql table<br><br>
</div>
<form name='import' method='post' enctype='multipart/form-data'>
<input type='file' name='file' /><br />
<input type='submit' name='submit' value='Submit' />
</form>
<?php
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
while(($filesop = fgetcsv($handle, 1000,",")) !== false)
{
$name = $filesop[0];
$city = $filesop[1];
$sql = mysql_query("INSERT INTO myrecord (name,city) VALUES ('$name','$city')");
$c = $c + 1;
}
if($sql)
{
echo "You database has imported successfully. You have inserted ". $c ." recoreds";
}
else
{
echo "Sorry! There is some problem.";
}
}
?>
OUPUT:
create table myrecord
(id int primary key auto_increment,
name varchar(200),
city varchar(200)
);
STEP 2 :now write code for import.php file:
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "t";
$conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
mysql_select_db("$database", $conn) or die(mysql_error());
?>
<html>
<body>
<div >Import Excelsheet Data in mysql table<br><br>
</div>
<form name='import' method='post' enctype='multipart/form-data'>
<input type='file' name='file' /><br />
<input type='submit' name='submit' value='Submit' />
</form>
<?php
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
while(($filesop = fgetcsv($handle, 1000,",")) !== false)
{
$name = $filesop[0];
$city = $filesop[1];
$sql = mysql_query("INSERT INTO myrecord (name,city) VALUES ('$name','$city')");
$c = $c + 1;
}
if($sql)
{
echo "You database has imported successfully. You have inserted ". $c ." recoreds";
}
else
{
echo "Sorry! There is some problem.";
}
}
?>
OUPUT:
Demikianlah Artikel PHP CODE EXAMPLE FOR IMPORTING CSV FILES
Sekianlah artikel PHP CODE EXAMPLE FOR IMPORTING CSV FILES kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel PHP CODE EXAMPLE FOR IMPORTING CSV FILES dengan alamat link https://othereffect.blogspot.com/2016/08/php-code-example-for-importing-csv-files.html
0 Response to "PHP CODE EXAMPLE FOR IMPORTING CSV FILES"
Post a Comment