CHECKING TO SEE IF AN EMAIL ADDRESS (ACCOUNT) EXISTS IN THE ACCOUNTS DATABASE - Aug 6th, 2012


In my organization’s scenario, if a member has not paid their dues for a period of 2 years their record is deleted
from the database.

To deal with those members who still have a record in the database, I created (with a lot of help from Jason Sauchuk
from Interactive Tools) a function that checked a prospective member’s e-mail and reported whether their account still
exists.

Here’s what I did.

On the member signup page I created this form with the following explanatory text. (I'll show the form in the context of
the page code below)

To find out if you're still in our member database, enter the e-mail address you used to sign up with in the box below
and click on "submit". If your records are found, all you’ll have to do to reinstate your account is to pay
your current dues. Once your payment is processed, you’ll receive an e-mail with your login username and password.
Then you’ll again be able to enjoy the benefits of membership and update your member profile information.



<?php if (!@$CURRENT_USER): ?>
<form action="?" method="post">
<input type="hidden" name="action" value="pastInformation" />
<span class="body-text-bold">Enter your e-mail address:</span>
<input type="text" name="pastInformation" value="<?php echo htmlspecialchars(@$_REQUEST['pastInformation']) ?>"
size="20" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php endif ?>



To display the appropriate error messages, like "please enter an email address" if the submitted form was empty, or
"your information was found" or "your information was not found" on the member page, I added the following to the top of
the page after the record calls:



<?php
// clear errors and set form to show on page load
$errorsAndAlerts = "";
$showForm = true;

if (@
$_REQUEST['submit']) {
$showForm = false;
if (!@
$_REQUEST['pastInformation']) {
$emptyField = "<span class='heading-text-yellow'>Please enter an email address</span>\n";
$showForm = true;
}
}
// error checking
$errorsAndAlerts = alert();

if (@
$CURRENT_USER) {
$errorsAndAlerts = "<span class='heading-text-yellow'>YOU ARE ALREADY LOGGED IN!</span><a class='special'
href='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>CLICK HERE TO CONTINUE TO THE WEB SITE</a> or <a class='special'
href='?action=logoff'>LOG OUT</a>.";
}

?>


I wanted the form and instructions to show along with the, "please enter an email address" error message and wanted it
to be hidden if the email address was either found or not found in the accounts database.

I added this code to the body of the page:


<?php if (@$emptyField): ?>
<?php $showform = true; ?>
<div >
<br />
<?php echo $emptyField; ?><br /></div>
<?php elseif (@$errorsAndAlerts): ?>
<?php $showform = false; ?>
<div ><br />
<?php echo $errorsAndAlerts; ?><br />
</div>

<?php else: ?>

...some code and text...

<?php if ($showForm == 'true'): ?>

... some text...

<?php if (!@$CURRENT_USER): ?>
<form action="?" method="post">
<input type="hidden" name="action" value="pastInformation" />
<span class="body-text-bold">Enter your e-mail address:</span>
<input type="text" name="pastInformation" value="<?php echo htmlspecialchars(@$_REQUEST['pastInformation']) ?>"
size="20" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php endif ?>

...more instructions...

<?php endif ?>


In the websiteMembership plugin in the "// perform website login actions" section, I added the following to the list of
actions:



if (@$_REQUEST['action'] == 'pastInformation') { _websiteLogin_pastInformation(); }


Then, immediately before the "// perform website login actions" section of code, I added this block of code to check for
the existence of the email address in the accounts database.



// Existing Account Request
function _websiteLogin_pastInformation() {
global $SETTINGS, $TABLE_PREFIX;

$exists=0;
if(@$_REQUEST['pastInformation']){
$where = "email ='".mysql_escape(@$_REQUEST['pastInformation'])."'";
$exists=mysql_select_count_from('accounts',$where);
}

if ($exists) {
alert("<span class='heading-text-yellow'>Congratulations!!!<br />Your Account Exists</span><br /><span
class='your_class'>You do not need to create a new account.</span>\n");
}
if (!$exists) {
alert("<span class='your_class'>Sorry!!!<br />Your Account No Longer Exists</span><br /><span class='your_class'>You'll
have to fill out a new membership application after you you've paid your current year's dues.<br />To search for your
information using another email address <a href='becomeamember.php'><span class='your_class'>CLICK HERE</span></a><br
/></span>\n");

}
}


To make contents that show on your viewer dependent on the values returned, you can use a combination of:


<?php if ($showForm == 'true'): ?> your contents <?php endif ?>


and


<?php if ($showForm = 'false' && (strpos($errorsAndAlerts,'Your-case-sensitive--text-string'))): ?> your contents <?php
endif ?>


or add a ! before the variables (!$showform = etc. to cover situations that do not meeting those criteria




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service