0

hi all
could someone plz help me out in validating csv file(excel sheet) before i can insert it into the database?:?:
i hv the code for uploading but not validating
reply ASAP.
cheers
coder

5
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by morecambe
0

Ok, here's a hint: CSV files are normally just plain text. You have to read the information in before you can do anything with it.

0

Hi
thanks for the reply. But i hv already done what you hv sent me....
my csv contains firstname,lastname,email id. So i have to validate the
email and not allow specialchar other than @. The following is my code.....

if($_REQUEST['submit'])
{ 
 $errmsg="";
 $contents = file ('./email_entries.csv'); 
 for($i=0; $i<sizeof($contents); $i++)
   { 
      $line = trim($contents[$i],'",$#!%&^*()'); 
      $arr = explode(',', $line); 

 if(!$arr)
   {
   $errmsg.='Invalid CSV file! Please check again.';
   }
   else{
   $sql = mysql_query("insert into employees(first_name,last_name,email_id) values ('".$arr[0]."','".$arr[1]."','".$arr[2]."')");
         }

     }
  }

Edited by happygeek: fixed formatting

0

PHP_CODER did you finish your project and learn how to validate the csv contents. I'm exactly at the point where you were when you asked your qustion. If you did find out how to do the validation please can you post the answer.

Thx

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.