Jump to content

[SOLVED] Registration Failed


Anxious

Recommended Posts

Lets put this straight, I don't recieve errors. It just fails to register, I believe this is failure writing to the database. Here is Database, Session, Process.php for the register form.

 

Database.php

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

 

Session.php

<?php function register($subuser, $subpass, $subemail, $subday, $submonth, $subyear, $sublocation, $subgender){
      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");
  }
  }
  
  /* Day error checking */
  $field = "day"; //Use field name for day
  if(!$subday || strlen($subday = trim($subday)) == 0){
  $form->setError($field, "* Day 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");
	  }
	  
  /* Month error checking */
  $field = "month"; //Use field name for month
  if(!$submonth || strlen($submonth = trim($submonth)) == 0){
  $form->setError($field, "* Month not selected");
  }
  
  /* Year error checking */
  $field = "year"; //Use field name for year
  if(!$subyear || strlen($subyear = trim($subyear)) == 0){
  $form->setError($field, "* Year not selected");
  }
	  
  /* Gender error checking */
  $field = "gender"; //Use field name for gender
  if(!$subgender || strlen($subgender = trim($subgender)) == 0){
          $form->setError($field, "* Gender 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, $subday, $submonth, $subyear, $sublocation, $subgender)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser,$subemail,$subpass,$sublocation,$subgender);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   } ?> 

 

Process.php

<?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['day'], $_POST['month'], $_POST['year'], $_POST['location'], $_POST['gender']);
      
      /* 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);
      }
   } ?> 

 

Session.php checks for errors, and then carries on with the processing.

Process.php forwards the values to the Database.php

Database.php then puts the values into the database.

 

"dob" = Date Of Birth, which is... Day, Month, Year (as seperate menu's on the register form) combined to make something like "24/january/2009" underneath dob on the database.

 

When you register, it says 'registration failed' as you hit submit. It notices when theres errors, so I'm guessing its errors writing to the database.

 

Any ideas?

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/153239-solved-registration-failed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.