Showing posts with label Upload csv file into mysql. Show all posts
Showing posts with label Upload csv file into mysql. Show all posts

Friday, February 24, 2012

Upload csv file into mysql database using php

<?php
session_start();
include("setting.php");

$email=$_SESSION['email'];


$uid=uid($email);

if ($_FILES[csv][size] > 0) {
$pagename=ucfirst($_POST['pagename']);
$kk=mysql_query("insert INTO pages (headertitle,url,userid) values('$pagename','','$uid') ")
 or die(mysql_error());
$pageid=mysql_insert_id();
$url="mlp.php/".$uid."/".$pageid;
$uup=mysql_query("UPDATE pages SET     url='$url'  WHERE pageid ='$pageid' ")
 or die(mysql_error());
   //get the csv file
    $file = $_FILES[csv][tmp_name];
    $handle = fopen($file,"r");
   
    //loop through the csv file and insert into database
    do {
        if ($data[0]) {
       
            mysql_query("INSERT INTO excel (pageid,userid,header_title,url_logo,text1,url_image1,text2,url_image2,cellno,
email,address,footer,link1_name,link1_url,link2_name,link2_url,link3_name,link3_url) VALUES
('$pageid','$uid','".addslashes($data[0])."','".addslashes($data[1])."'
,'".addslashes($data[2])."','".addslashes($data[3])."','".addslashes($data[4])."'
,'".addslashes($data[5])."','".addslashes($data[6])."','".addslashes($data[7])."'
,'".addslashes($data[8])."','".addslashes($data[9])."','".addslashes($data[10])."'
,'".addslashes($data[11])."','".addslashes($data[12])."','".addslashes($data[13])."'
,'".addslashes($data[14])."','".addslashes($data[15])."'
                )
            ");
        }
    } while ($data = fgetcsv($handle,1000,",","'"));
    //

    //redirect
    header('Location: createnewpages.php?success=1');

}
?>

Popular Posts