View Single Post
Old 11-16-2012, 02:29 PM   PM User | #15
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
Fou-Lu,

I have scussesfully coded below code for exporting CSV file in to Mysql but now I want to know how many of the lines ignored while inserting ...that should be a error message to be echoed to the user ..


PHP Code:
<?php
session_start
();
include_once 
"C:/xampp/htdocs/SAM/include/database.php";
$myusername $_SESSION['myusername']; //user who updating

$file            $_FILES['up_file']['tmp_name'];//"new_user_verf.csv";
$fp             fopen($file,"r");
$length         8096/// have to be optional length ...
$fildDelineate  ','/// or "|" ... declare what you need
$counter        0// to omission first row if it is table headers


while( !feof($fp) ) {
  
$value fgetcsv($fp$length$fildDelineate);
  
/*print_r($value);*/
  
$date date('Y-m-d H:m:s',strtotime($value[0]));
   
     
$importSQL "INSERT IGNORE INTO $tbl_name0 (`Account_Create_datetime`,`Analyst`,`Acc_User_Name`,`Email_Address`,`User_Ip`)
       VALUES ('"
.$date."','".$myusername."','".$value[1]."','".$value[2]."','".$value[3]."')";
     
$resultmysql_query($importSQL) or die(mysql_error());
      
$counter++;
}
fclose($fp);
if (
$result==1){
$_SESSION['Notify']['type'] = 'Sucess Message:';
$_SESSION['Notify']['msg'] = 'Uploaded total number of->'.$counter.'<-records in to the database.\n';
header("location:/SAM/TEST/test.php") or die("record not inserted");
}
elseif(
$result==IGNORE){
$_SESSION['Notify']['type'] = 'Error Message:';
$_SESSION['Notify']['msg'] = 'Could not upload, number of->'.$counter.'<-records in to the database.\n';
header("location:/mym/new_user/new_user.php") or die("record not inserted");
}
else{
$_SESSION['Notify']['type'] = 'Error Message:';
$_SESSION['Notify']['msg'] = 'Some how messed up, check with your admin!!!';
header("location:/SAM/TEST/test.php") or die("record not inserted");
}
echo 
"Imported successfully!";
?>

Any suggestion appreciated.....

Regards,
Nani
nani_nisha06 is offline   Reply With Quote