0

This is the code at line 23:

foreach($form->getErrorArray() as $m){
           $x .= "".$m." + ";
header("Location: Form_Display.php?message=".$x."")

Gives me two error messages
1. Passwords don't match
2. Email not entered

I've banged my head out, smoked a carton of cigarettes and had a quiet meditation session after raging.
I can't figure out why and either if you can help me, or just offer constructive criticism i'll gladly take it. I just started php with some background in OO languages if any one has tips.

Code in order of calling functions:

<?php
function procRegister(){
      global $session, $form;
      /* Convert username to all lowercase (by option) */
      if(ALL_LOWERCASE){
         $_POST['Username'] = strtolower($_POST['Username']);
      }
      /* Registration attempt */
      $retval = $session->register($_POST['Username'], $_POST['Password1'], $_POST['Email Address'],
        $_POST['password2'], $_POST['Confirm Email Address']);
      
      /* Registration Successful */
      if($retval == 0){
         $_SESSION['reguname'] = $_POST['Username'];
         $_SESSION['regsuccess'] = true;
         header("Location: home_display.php");
      }
      /* Error found with form */
      else if($retval == 1){
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         foreach($form->getErrorArray() as $m){
           $x .= "".$m." + ";
         header("Location: Form_Display.php?message=".$x."");
      }
      }
      /* Registration attempt failed */
      else if($retval == 2){
         $_SESSION['reguname'] = $_POST['Username'];
         $_SESSION['regsuccess'] = false;
         header("Location: Form_Display.php?not");
      }
   }
   
//inside session.class.php
function register($subuser,$subpass,$subemail,$c_pass,$c_email,$home=NULL,$bday=NULL){
      global $database, $form, $mailer;  //The database, form and mailer object
      
      /* Username error checking */
      $field = "user";  //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
         $form->setError($field, "* Username not entered");
      }
      else{
         /* Spruce up username, check length */
         $subuser = stripslashes($subuser);
         if(strlen($subuser) < 5){
            $form->setError($field, "* Username below 5 characters");
         }
         else if(strlen($subuser) > 30){
            $form->setError($field, "* Username above 30 characters");
         }
         /* Check if username is not alphanumeric */
         else if(!preg_match("/^([0-9a-z])+$/", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
         /* Check if username is reserved */
         else if(strcasecmp($subuser, GUEST_NAME) == 0){
            $form->setError($field, "* Username reserved word");
         }
         /* Check if username is already in use */
         else if($database->usernameTaken($subuser)){
            $form->setError($field, "* Username already in use");
         }
         /* Check if username is banned */
         else if($database->usernameBanned($subuser)){
            $form->setError($field, "* Username banned");
         }
      }

      /* Password error checking */
      $field = "password";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      else{
         /* Spruce up password and check length*/
         $subpass = stripslashes($subpass);
         if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
         }
         /* Check if password is not alphanumeric */
         else if(!preg_match("/^([0-9a-z])+$/", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }
         else if($subpass!=$c_pw){
            $form->setError($field, "* Passwords don't match");
             }
          }
      /* Email error checking */
      $field = "email";  //Use field name for email
      if(!$subemail || strlen($subemail = trim($subemail)) == 0){
         $form->setError($field, "* Email not entered");
      }
      else{
         /* Check if valid email address */
         $regex = "/^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                 ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                 ."\.([a-z]{2,}){1}$/";
         if(!preg_match($regex,$subemail)){
            $form->setError($field, "* Email invalid");
         }
         else if($subemail!=$c_email){
           $form->setError($field, "* Emails don't match");
         }
         $subemail = stripslashes($subemail);
      }

      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
         return 1;  //Errors with form
      }
      /* No errors, add the new account to the db */
      else{
         if($database->addNewUser($subuser, md5($subpass),$subemail,$home,$bday,$sid)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser,$subemail,$subpass);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   } 
   
//in database.class.php
function addNewUser($username,$password,$email,$home=NULL,$bday=NULL,$sid=NULL){
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
      $q .= "INSERT INTO ".TBL_USERS."";
      $q .= "SET username='$username', password='$pw', ";
      $q.= "SET email='$email', userlevel='$ulevel', timestamp='$time', ";
      if($home='' || $home=NULL)
        $q .= "home='CAPITAL', ";
      else
        $q .= "home='$home', ";
      
      if($bday='' || $bday=NULL)
        $q .= "birthday='11/04/1991', ";
      else
        $q .= "birthday='$birthday', ";
        
      $q .= "sessionid='1';";

      return mysql_query($q, $this->connection);
   }
   
?
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by joeyxaza
0

for the password error, can you check the name you assigned to it in the main html form and make sure you closed all your if/else braces.
for the email issue (if(!$subemail || strlen($subemail = trim($subemail)) == 0){) try removing the trim() function and just leave it as
strlen($subemail == 0)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.