User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,560 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,634 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

validating CSV before saving in MYSQL

Join Date: Dec 2006
Posts: 34
Reputation: php_coder is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
php_coder php_coder is offline Offline
Light Poster

Re: validating CSV before saving in MYSQL

  #4  
Dec 18th, 2006
Originally Posted by DennisP View Post
http://codewalkers.com/seecode/585.html

If you're lazy like me.

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

}
}
Reply With Quote  
All times are GMT -4. The time now is 1:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC