This topic is locked

can I validate registrations against allowed table

4/10/2007 7:59:52 PM
PHPRunner General questions
P
powerchuck author

I am creating an online membership roster for a club. I have created the database and fields and all works well. But right now anyone who visits my site and wants to register can, and then all registered users have access to club data. I wish to restrict access to register only those I who are already club members (and future members).
I already have a list of all members email addresses, so I figured I'd create a seperate table called _auth_email with one field called email. I could populate this table quickly myself. Then when members went to the website to register I wanted the registration to check this table and verify that the potential registrant's email was indeed on the list of people "allowed to register"
I can see in Events (step 11 of 12) where I can Check if a specific record exists before registration. But I can't seem to get the syntax right. If they are on the valid list of emails in the _auth_email table then the registration should complete if not they should get message - " sorry blah blah blah" and probably be redirected to the login page.
I've searched the forums and such but can't seem to find this scenario. Sorry for the lack of sql / php syntax, but that's why I opted for this software as I didn't have to learn too much more.
[codebox]function BeforeRegister($userdata)

{
// Parameters:

// $userdata - Array.

// Each field on this form represented as 'Field name'-'Field value' pair
//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from _auth_email where email='AnyValue'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

return true;

{

// if dont exist do something else

}
//** Display a message on the Web page ****

echo "sorry your email is not in our members database";
//** Redirect to another page ****

header("Location: login.php");

exit();
// return true if you like to proceed with registration

// return false in other case
}[/codebox]

J
Jane 4/11/2007

Hi,
try to use following event code:

function BeforeRegister($userdata)

{

global $conn;

$strSQLExists = "select * from _auth_email where email='".$userdata["EmailField"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

return true;

}

else

{

echo "sorry, your email is not in our members database";

return false;

}

}



where EmailField is your actual field name on the registration page.

P
powerchuck author 4/11/2007

Thanks, that helped although when I tried to add a record to the authorized_emails I got this response
auth_email, Add new record

<<< Record was NOT added >>>
Unknown column 'email' in 'field list'
--------------------------------------------------------------------------------
Back to list
authorized_email
--------------------------------------------------------------------------------

  • Required field
    I'll keep debugging - any suggestions?

J
Jane 4/12/2007

Hi,
you need to replace email with your actual field name in the _auth_email table:

$strSQLExists = "select * from _auth_email where email='".$userdata["EmailField"]."'";

P
powerchuck author 4/12/2007

Hi,

you need to replace email with your actual field name in the _auth_email table:


Awesome - got it fixed, works like a charm. Thanks