Function Problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx, myname
you@xxxxxxx, yourname
us@xxxxxx, 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@xxxxxx, myname
me@xxxxxx, myname
me@xxxxxx, myname
you@xxxxxxx, yourname
you@xxxxxxx, yourname
you@xxxxxxx, yourname
us@xxxxxx, ourname
us@xxxxxx, ourname
us@xxxxxx, 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

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux