Member Form Validation

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

[/code]

If you know what I have done wrong, please post the answer in detail.

Hi blackhawk,

The reason you are getting the else case is that your if…elseif statements do nothing, in other words, they only contain comments.

Also, if you want to check if that position has already been filled, I see an easy solution.

Add a column onto your temp table for position, as well as to the non-temp table for member records.

Then, inside your if…elseif statements, make a variable $position, and set it based on the entered code, ie if the code entered was 123456, $position = “Standard”.

Then when you do your insert into the temp table, you can include the position variable.

Now, before you do the insert into temp, why not query the table for non-temp records for the positions column, where the position is equal to the code entered, if the code entered was for a “only one” position.

If you find that the code entered is for a position that is filled, then obviously you can display a different message on screen and eliminate sending the eMail and continuing on doing unnecessary procedures.

If you find that the code entered is for a position that is not filled, and is a “only one” position, then continue processing, and if the code entered is for a standard membership, you need not run query to check at all.

Simply place the coding for the above within your if…elseif statements since you cannot leave those blank.

Hope this helps.

Robert

In the database tables “temp” and “users” I have a column named “tsa_confirm”. That holds the codes. I need the actual codes in the tables, not the position names. Later on, I will call their club position with those codes. They will also be used for other parts of the website that I haven’t created yet.

If you look in the PHP script a few lines down, you will see a variable named “query”. That variable is what is supposed to grab all of the information on the form and send it to the database.

Is this what you suggest I do:
[php]
if($tsa_confirm == 123456){ //standard member
if($_POST($tsa_confirm) ) {
}else{
$message = “Invalid Code”;
}

                        }elseif($tsa_confirm == 213456){  //president
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

            }elseif($tsa_confirm == 312456){  //vice-president
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

            }elseif($tsa_confirm == 412356){  //secretary
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

                        }elseif($tsa_confirm == 512346){  //treasurer
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

           }elseif($tsa_confirm == 612345){  //sargent-at-arms
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

              }elseif($tsa_confirm == 135246){  //historian
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }

              }elseif($tsa_confirm == 246135){  //admin
                                 if($_POST($tsa_confirm) ) {
                                   }else{
                                          $message = "Invalid Code";
                                   }
       }else{
            $message = "Please enter a vaild TSA Member Confirm Password!"

[/php]

I know I didn’t add in the part that checks the database tables for club officer passwords. I’m still trying to figure how to exactly how to do it. You explained it well, but their are still some grey areas.

I’m still learning PHP, so I’m a little slow at figuring out how to code what I need.

Sponsor our Newsletter | Privacy Policy | Terms of Service