Jump to content

Registration- database


czukoman20

Recommended Posts

Hey everyone, i am having a problem with my coding. not sure why its not working.

 

Please don't mind my organization right now, because i want this to work b4 i reorganize

 

My registration isn't working for some reason i cant find out.

 

When u input the values into the form, and hit submit, it hits my REGISTRATION FAILED error

 

Here is the registration page code

Please just take a skim through the code. because i have looked at the code a million times. and i can't seem to find anything. 

I know its long.



<form action="process.php" method="post">
<table width="478" border="0" align="left" cellpadding="3" cellspacing="0">
<tr><td width="272">Username:</td><td width="144"><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>" /></td><td width="44" rowspan="5"><? echo $form->error("user"); ?></td></tr>
<tr>
  <td>Password:</td>
  <td width="144"><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>" /></td>
</tr>
<tr>
  <td>Email:</td>
  <td width="144"><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>" /></td>
</tr>
<tr>
  <td>First Name:</td>
  <td width="144"><input type="text" name="realname" maxlength="50" value="<? echo $form->value("realname"); ?>" /></td>
</tr>
<tr>
  <td>Last Name:</td>
  <td><input type="text" name="last_name" maxlength="50" value="<? echo $form->value("last_name"); ?>" /></td>
</tr>
<tr><td>Mailing Address:</td><td><input type="text" name="address" maxlength="50" value="<? echo $form->value("address"); ?>" /></td><td><? echo $form->error("address"); ?></td></tr>
<tr>
  <td>City:</td><td><input type="text" name="city" maxlength="50" value="<? echo $form->value("city"); ?>" /></td><td><? echo $form->error("city"); ?></td></tr>
<tr>
  <td>State:</td><td><input type="text" name="state" maxlength="50" value="<? echo $form->value("state"); ?>" /></td><td><? echo $form->error("state"); ?></td></tr>
<tr>
  <td>Zip Code:</td>
<td><input type="text" name="zip" maxlength="50" value="<? echo $form->value("zip"); ?>" /></td><td><? echo $form->error("zip"); ?></td></tr>
<tr>
  <td><div align="left">Phone Number(555-555-5555):
    </div></td>
  <td align="right"><input type="text" name="phone" maxlength="50" value="<? echo $form->value("phone"); ?>" /></td>
</tr>
<tr><td colspan="2" align="left"><input type="submit" value="Join!"  />
  <input type="hidden" name="subjoin" value="1" />
</td>
</tr>
</table>
</form>

 

Here is the process.php code that it links to.

  
   /* User submitted registration form */
      else if(isset($_POST['subjoin'])){
         $this->procRegister();
      }


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['realname'], $_POST['last_name'], $_POST['address'],$_POST['city'],$_POST['state'], $_POST['zip'], $_POST['phone']);
      
      /* 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);
      }
   }
   

 

here is the session that it goes through after that.

   function register($subuser, $subpass, $subemail, $subrealname, $sublast_name, $subaddress, $subcity, $substate, $subzip, $subphone){
      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");
         }
         /**
          * Note: I trimmed the password only after I checked the length
          * because if you fill the password field up with spaces
          * it looks like a lot more characters than 4, so it looks
          * kind of stupid to report "password too short".
          */
      }
      
      /* 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);
      }

      /* 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, $subrealname, $sublast_name, $subaddress, $subcity, $substate, $subzip, $subphone)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser, $subemail, $subpass, $subrealname, $sublast_name, $subphone);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   }
   

and lastly the database code that creates the database

   function addNewUser($username, $password, $email, $realname, $last_name, $address, $city, $state, $zip, $phone){
      $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." VALUES ('$username', '$password', '0', $ulevel, '0', '$email', $time, '$realname', '$phone', '$userid_2', '$address', 'none', 'none', 'none', 'none', 'none', '$state', 'none', '$zip' ,'$last_name')";
      return mysql_query($q, $this->connection);
   }

Link to comment
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.