how to upload csv file on database with php

how to upload csv file on database with php 

<?php  


if(isset($_POST["submit"]))

{

 if($_FILES['file']['name'])

 {

  $filename = explode(".", $_FILES['file']['name']);

  if($filename[1] == 'csv')

  {

   $handle = fopen($_FILES['file']['tmp_name'], "r");

   while($data = fgetcsv($handle))

   {

    $item1 = mysqli_real_escape_string($conn, $data[0]);  

                $item2 = mysqli_real_escape_string($conn, $data[1]);

$item3 = mysqli_real_escape_string($conn, $data[2]);  

                $item4 = mysqli_real_escape_string($conn, $data[3]);

$item5 = mysqli_real_escape_string($conn, $data[4]);  

                $item6 = mysqli_real_escape_string($conn, $data[5]);

$item7 = mysqli_real_escape_string($conn, $data[6]); 

$item8 = mysqli_real_escape_string($conn, $data[7]);

//$item9 = mysqli_real_escape_string($conn, $data[8]);

                //$item2 = mysqli_real_escape_string($connect, $data[1]);

                 date_default_timezone_set("Asia/Kolkata");

$datee=date( 'd-m-Y');

//

$url1=strtolower($item8);

$url14= clean($url1);

$incoming_time = date('Y-m-d h:i a');

$url = str_replace('--', '-', $url14);

$url = str_replace(' ', '-', $url);

                $query = "INSERT into product_master(cateId,sub_cat_id,sub_sub_cat_id,mainPrice,saleprice,shortDesc,longDesc,productName,url) values('$item1','$item2','$item3','$item4','$item5','$item6','$item7','$item8','$url')";

                mysqli_query($conn, $query);

   }

   fclose($handle);

   echo "<script>alert('Import done');</script>";

  }

 }

}


$message = '';





?>                   

                                   <form method="post" enctype="multipart/form-data">

   <div align="left">  

    <label>Select CSV File:</label>

    <input type="file" name="file" />

   

    <input type="submit" name="submit" value="Import" class="btn btn-info" />

    

    

   

   </div>

  </form> 

Comments

Popular posts from this blog

how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php

How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php

How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python