Specifications

LISTING 28.3 Continued
else
{
echo “<p>Sorry, that email address is already registered here.”;
echo “<p>You will need to log in with that address to change “
.” Web settings.”;
return false;
}
}
else // new account
{
$query = “insert into subscribers
values (‘$details[email]’,
‘$details[realname]’,
‘$details[mimetype]’,
password(‘$details[new_password]’),
0)”;
if(db_connect() && mysql_query($query))
{
return true;
}
else
{
echo “Could not store new account.<br><br><br><br><br><br>”;
return false;
}
}
}
}
This function first checks that the user has filled in the required details.
If this is okay, the function will then either create a new user, or update the account details if the
user already exists. A user can only update the account details of the user he is logged in as.
This is checked using the
get_email() function, which retrieves the email address of the user
who is currently logged in. Well return to this later, as it uses session variables that are set up
when the user logs in.
Logging In
If a user fills in the login form we saw back in Figure 28.4 and clicks on the Log In button, she
will enter the index.php script with the $email and $password variables set. This will activate
the login code, which is in the pre-processing stage of the script, as follows:
Building a Mailing List Manager
C
HAPTER 28
28
BUILDING A
MAILING LIST
MANAGER
675
34 7842 CH28 3/6/01 3:46 PM Page 675