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

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.

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]."')");
         }

     }
  }

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.