Jump to content

Recommended Posts

I've seen a post of this before, I'm having similar problems, using the same format.

Location and Gender error fields are getting mixed up, aswell as not getting a value. If I removed the gender, so it's back to how it was before. It worked. Can somebody assist me.

 

I use, Register.php, Process.php, Database.php, Session.php.

 

There big code files.

 

Hope you can assist, Thanks.

Anxious

Link to comment
https://forums.phpfreaks.com/topic/152986-error-field-problems/
Share on other sites

I've seen a post of this before, I'm having similar problems, using the same format.

Location and Gender error fields are getting mixed up, aswell as not getting a value. If I removed the gender, so it's back to how it was before. It worked. Can somebody assist me.

 

I use, Register.php, Process.php, Database.php, Session.php.

 

There big code files.

 

Hope you can assist, Thanks.

Anxious

sorry, this isn't the Psychic PHPFreaks network, it's just the PHPFreaks network .. we actually need to see code to troubleshoot it.

 

just mentioning the names of your scripts doesn't spark any ideas.

Link to comment
https://forums.phpfreaks.com/topic/152986-error-field-problems/#findComment-803453
Share on other sites

<?php    function register($subuser, $subpass, $subemail, $sublocation){
      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(!eregi("^([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 = "pass";  //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(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }
      }
      
      /* 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(!eregi($regex,$subemail)){
            $form->setError($field, "* Email invalid");
		$subemail = stripslashes($subemail);
         }
      else if($database->emailTaken($subemail)){
      $form->setError($field, "* Email already in use");
  }
  }
  
  	  /* Gender error checking */
  $field = "gender"; //Use field name for gender
  if(!$subgender || strlen($subgender = trim($subgender)) == 0){
          $form->setError($field, "* Gender not selected");
	  }
  
  	  /* Location error checking */
  $field = "location"; //Use field name for location
  if(!$sublocation || strlen($sublocation = trim($sublocation)) == 0){
      $form->setError($field, "* Location not selected");
	  }

      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
         return 1;  //Errors with form
      }
      /* No errors, add the new account to the */
      else{
         if($database->addNewUser($subuser, md5($subpass), $subemail, $sublocation)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser,$subemail,$subpass,$sublocation);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   } ?> 

 

 

<?php    function procRegister(){
      global $session, $form;
      /* Convert username to all lowercase (by option) */
      if(ALL_LOWERCASE){
         $_POST['user'] = strtolower($_POST['user']);
      }
      /* Registration attempt */
      $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['gender'], $_POST['location']);
      
      /* Registration Successful */
      if($retval == 0){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = true;
         header("Location: ".$session->referrer);
      }
      /* Error found with form */
      else if($retval == 1){
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
      /* Registration attempt failed */
      else if($retval == 2){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = false;
         header("Location: ".$session->referrer);
      }
   } ?>

Link to comment
https://forums.phpfreaks.com/topic/152986-error-field-problems/#findComment-803469
Share on other sites

change:

function register($subuser, $subpass, $subemail, $sublocation){

to:

function register($subuser, $subpass, $subemail, $subgender, $sublocation){

 

then

if($database->addNewUser($subuser, md5($subpass), $subemail, $sublocation)){

to

if($database->addNewUser($subuser, md5($subpass), $subemail, $subgender, $sublocation)){

 

And now I need to see your database.php file to finish

 

 

Link to comment
https://forums.phpfreaks.com/topic/152986-error-field-problems/#findComment-803491
Share on other sites

<?php    function addNewUser($username, $password, $email, $gender, $location){
      $time = date("F j, Y, g:i");
      /* 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." VALUES ('$username', '$password', $ulevel, '$email', '$time',  '$gender', '$location')";
      return mysql_query($q, $this->connection);
   } ?> 

 

I took ID on the database, so its always last, so I wont need to include the other bit you added in.

Link to comment
https://forums.phpfreaks.com/topic/152986-error-field-problems/#findComment-803515
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.