I recently added a “Member Confirmation Code” area to the registration form on a website I’ve been working on. This is to prevent non-TSA members from creating a profile. As usual, something isn’t working right.
I named the TSA Member Confirmation code: “$tsa_confirm”.
You will notice that I used the “if/elseif” statement. That is because there are mutilple codes that can be entered into the “tsa_confirm” field. Each of these codes will be affiliated with a “title”.
As an example, if someone entered “12345” into the $tsa_confirm field, their profile would echo"title: standard member". If they entered “213456” into the field, their profile would echo “title: president”.
Right now, if you enter “12345 (standard member code)” the “$tsa_confirm” field, the “else” message shows up. If you type any of the other codes into the field, no message shows up and the form doesn’t send. I have checked the code and experimented with what could be wrong for hours and I can’t seem to catch it.
There is one aspect of this form that I don’t know how to apply to the “$tsa_confirm” codes. There is only one club president, vice-president, ect. Therefore, I would like the form to check the database for the officer codes. If a user already has that tsa_confirm code, I need the form to echo “That officer position is filled”.
I DON’T WANT THIS APPLIED TO THE “Standard Member” code.
Here is the PHP Validation script:
[php]if($_POST[‘sign_up’]) {
$username = $_POST[‘username’];
$email = $_POST[‘email’];
$password = $_POST[‘password’];
$password_confirm = $_POST[‘password_confirm’];
$tsa_confirm = $_POST[‘tsa_confirm’];
$course = $_POST[‘course’];
if(!empty($username) && !empty($email) && !empty($password) && !empty($password_confirm) && !empty($tsa_confirm)) {
if(strlen($username) > 2) {
if(strlen($username) < 33) {
if(strlen($password) >=3) {
if(strlen($password) <=32) {
if($password_confirm == $password) {
if(filter_var($email, FILTER_VALIDATE_EMAIL) == $email) {
if($tsa_confirm == 123456){//standard member
}elseif($tsa_confirm == 213456){//president
}elseif($tsa_confirm == 312456){//vice-president
}elseif($tsa_confirm == 412356){//secretary
}elseif($tsa_confirm == 512346){//treasurer
}elseif($tsa_confirm == 612345){//sargent-at-arms
}elseif($tsa_confirm == 135246){//historian
}elseif($tsa_confirm == 246135){//admin
if($course != "Default") {
$code_confirm = md5(uniqid(rand()));
$query = "INSERT INTO temp (code, username, email, password, course, tsa_confirm) VALUES('".$code_confirm."', '".$username."', '".$email."', '".$password."', '".$tsa_confirm."', '".$course."')";
if($result = mysql_query($query)) {
$to = $email;
$subject = "Confirmation Email!";
$body = "You just registered to the website! \r\n";
$body .= "Click on the confirmation link to confirm your account! \r\n";
$body .= "http://www.my-testing-area.netne.net/confirmation.php?code=".$code_confirm;
$headers = "From:[email protected]";
$sent = mail($to, $subject, $body, $headers);
if($sent) {
$message2 = "You have successfully been signed up!<br /> A confirmation link has been sent to your account.<br /> Please click on the link to activate your account.";
} else {
$message2 = "Couldn't send confirmation email...";
}
} else {
$message2 = "Couldn't query the database".$query." : ".mysql_error();
}
} else {
$message2 = "Please select which course you are taking!";
}
}else{
$message2 = "Invalid TSA Member Confimation Code!";
}
} else {
$message2 = "Please enter a valid email!";
}
} else {
$message2 = "Both password fields MUST match!";
}
} else {
$message2 = "The password you entered cannot be more than 32 characters!";
}
} else {
$message2 = "The password you entered needs to be at least 3 characters long!";
}
} else {
$message2 = "The username you entered cannot be more then 32 characters!";
}
} else {
$message2 = "The username you entered needs to be at least 3 characters long!";
}
} else {
$message2 = “Some of the fields are empty!”;
}
} else {
$message2 = “Please enter your info to create a profile.”;
}[/php]
Here is the Registration Form:
[code]
Register
<?php echo $message2; ?>Username:
Email:
Password:
Repeat Password:
<?php echo $tsa_message;?> TSA Membership Code:
Current Engineering Course:
Default GTT IED CIM POE DE
If you know what I have done wrong, please post the answer in detail.