Function Problem
| From: | Chris Payne | Date: | Wed, 03 Dec 2003 05:57:53 +0000 |
| Subject: | Function Problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-31863@lists.php.net to get a copy of this message | ||
Hi there everyone,
This code works fine until I put it into my function, then it still works BUT however many lines are
in the file are multiplied. For example, if I have 3 lines with the following:
me@me.com, myname
you@you.com, yourname
us@us.com, ourname
In THEORY this should just print the above, HOWEVER, when it's being called as a function
it's giving me the following:
me@me.com, myname
me@me.com, myname
me@me.com, myname
you@you.com, yourname
you@you.com, yourname
you@you.com, yourname
us@us.com, ourname
us@us.com, ourname
us@us.com, ourname
When it is inserted into the DB. It might be something obvious, but here's the code below to
see if there's anything obvious i'm doing wrong.
Oh and i've checked and $userfile AND $delim are being picked up ok.
function db_importcsv($userfile,$delim) {
if ($userfile == ""){
$failed = 'yes';
} else {
$date = date('d m Y');
$row = 1;
$handle = fopen ("$userfile","r");
while ($data = fgetcsv ($handle, 5024, ",")) {
$num = count ($data);
$row++;
mysql_query ("INSERT INTO emaillist (EMail,name,date)
VALUES ('$data[0]','$data[1]','$date')
");
};
fclose ($handle);
$failed = "no";
};
return $failed;
};
Any help would be really appreciated, as i'm new to functions but enjoying it :-)
Chris