PDA

Click to See Complete Forum and Search --> : Mail List script


GingerNut
Oct 9th, 2002, 07:40 AM
Hi guys,

I have a script for a mail list, which adds the name and email address to a text file. I now deen to be able to add the street address, town, county and postcode. I tried modifying the script myself but can't get it to work. Could someone have a go or show me where I'm going wrong?

Here's the part of the script that adds the details to the text file:
sub add {

$dup = 0;

if (-e "$list")
{
open (FILE,"$list") || die "Can't open $list!\n";
@lines=<FILE>;
close(FILE);

foreach $line (@lines) {
&splitlist;
if ($uemail eq $email) {$dup = '1';}
}
}
if ($dup eq '0')
{
while (-f $listlock){select(undef,undef,undef,0.1);}
open(LOCKFILE, ">$listlock");

open (FILE,">>$list");
print FILE "$email=$name=$date\n";
close(FILE);

close(LOCKFILE);
unlink($listlock);
}

&printresult;
}


I tried doing this:

open (FILE,">>$list");
print FILE "$email=$name=$address=$town=$county=$postcode=$date\n";
close(FILE);

but it didn't work.

The Hobo
Oct 9th, 2002, 07:56 AM
Originally posted by GingerNut
Hi guys,

I have a script for a mail list, which adds the name and email address to a text file. I now deen to be able to add the street address, town, county and postcode. I tried modifying the script myself but can't get it to work. Could someone have a go or show me where I'm going wrong?

Here's the part of the script that adds the details to the text file:
sub add {

$dup = 0;

if (-e "$list")
{
open (FILE,"$list") || die "Can't open $list!\n";
@lines=<FILE>;
close(FILE);

foreach $line (@lines) {
&splitlist;
if ($uemail eq $email) {$dup = '1';}
}
}
if ($dup eq '0')
{
while (-f $listlock){select(undef,undef,undef,0.1);}
open(LOCKFILE, ">$listlock");

open (FILE,">>$list");
print FILE "$email=$name=$date\n";
close(FILE);

close(LOCKFILE);
unlink($listlock);
}

&printresult;
}


I tried doing this:

open (FILE,">>$list");
print FILE "$email=$name=$address=$town=$county=$postcode=$date\n";
close(FILE);

but it didn't work.

Why don't you do this in PHP and use a MySQL database? It'd be so much easier.

GingerNut
Oct 9th, 2002, 08:23 AM
Wouldn't know how.

JoshT
Oct 9th, 2002, 10:00 AM
What exactly is the problem or error message? And can't you use the flock() function for file locking?

GingerNut
Oct 9th, 2002, 10:35 AM
There is no error message. I just can't get it to write the postal address to the text file.

JoshT
Oct 9th, 2002, 01:31 PM
So what's it writing to the text file, empty strings between the '=' where the address parts should be?

GingerNut
Oct 9th, 2002, 02:28 PM
It writes the email address, the name and the date. Like this:

test@test.com=Test=Oct 08, 02 (15:59:52 BST)

The Hobo
Oct 9th, 2002, 02:43 PM
Originally posted by GingerNut
Wouldn't know how.

So learn?

Rather than posting here for everyone to fix your scripts for you. I've done a couple of them for you in the PHP forum. :rolleyes: