This is driving me insane, please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lppa2004
Forum Newbie
Posts: 2
Joined: Wed Mar 03, 2010 3:53 pm

This is driving me insane, please help

Post by lppa2004 »

ok i have been over this function many times and tried many different approaches and yet when i look at the code I dont see why it isnt working. Basically the code works until it reaches this section

Code: Select all

 
if ($pass1 == $pass2) {
        $owner=mysql_fetch_array(mysql_db_query($db_name, "SELECT * FROM $tbl_member"));
 
        if ($login == $owner[login]){
        $error="10";
        }
        elseif ($email == $owner[email]){
        $error="12";
        }
        
        else{$error="";}
 


When it reaches this section after verifying that the password matches the "confirm pass" it should be checking the database to verify if the username or email address exists.. if it does then it should error, when it doesnt error then it returns no error and the information is passed to the database... However for some reason it seems to be skipping the database login and email check. Im quite sure it is opening the database because the rest of my script uses a similar piece of code to open the database in other functions and it works fine..

Please help... i really need this to work otherwise im going to have people registering multiple times with the same email or username. Whats really sad is when i initially wrote this code I could of sworn i tested it and it worked perfectly fine. (NOTE: I can not take credit for all of the code a lot of it is from another persons work, but i have also done a lot of my own additions and modifications to it as well)

Code: Select all

 
function validate_member ($login, $pass1, $pass2, $email) {
global $db_name, $tbl_member;
 
$login_count = strlen($login);
$pass_count = strlen($pass1);
  if ($pass_count >= 6) {
  if ($pass_count <= 30) {
  if ($login_count >= 3) {
  if (eregi("^[a-z0-9_-]+$",$login)) {
  if (eregi( "^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$" , $email)) {
    if ($pass1 == $pass2) {
        $owner=mysql_fetch_array(mysql_db_query($db_name, "SELECT * FROM $tbl_member"));
 
        if ($login == $owner[login]){
        $error="10";
        }
        elseif ($email == $owner[email]){
        $error="12";
        }
        
        else{$error="";}
    } else {$error="20";}
  } else {$error="30";}
  } else {$error="02";}
  } else {$error="01";}
  } else {$error="04";}
  } else {$error="03";}
        //} else {$error="12";}
        //} else {$error="10";}
return $error;
}
 
Error Codes:
==================

Code: Select all

 
<?
/* $Id: include/error.php,v 0.2 2002/10/13 15:11:55 wibi Exp $ */
$strError01= "Your login must be no less than four characters in length.";
$strError02= "Your login may only contain alpha-numeric combinations, and you may only use the dash \"-\" or the underscore \"_\", spaces are not allowed.";
$strError03= "Your password must be no less than six characters in length.";
$strError04= "Your password must be no more than 30 characters in length.";
$strError10= "The username you have chosen is already in use, please choose another username.";
$strError12= "The email address has already been used for registration";
$strError15= "You are not logged in yet. Please login first.";
$strError20= "Verify Password Failed";
$strError25= "You must agree to the terms & conditions";
$strError30= "Invalid Email";
$strError40= "Reserved Character";
$strError50= "Verify New Password Failed";
$strError60= "Account Disabled, If you feel this is an error please <a href=contact.php>contact us</a>.";
$strError61= "You must be an administrator to access this feature.";
$strError70= "Invalid login or password combination";
$strError75= "Invalid login name";
$strError80= "You have not fully completed the required fields";
$strError81= "Error in adding event";
$strError85= "You must fill out all fields before continuing";
$strError99 = "The username and password combination doesnt match our database";
$strError5= "You are logged in $login, <a href=logout.php>Please logout before continuing</a>";
 
?>
 
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: This is driving me insane, please help

Post by scarface222 »

try this

Code: Select all

if ($pass1 == $pass2) {
         $owner=mysql_fetch_array(mysql_query($db_name, "SELECT * FROM $tbl_member"));
  
         if ($login == $owner['login']){
         $error="10";
         }
         else if ($email == $owner['email']){
         $error="12";
         }
        
         else{$error="";}
if not try using a while statement after your query like so to define variables, that is how I do my queries anyway

Code: Select all

while ($row = mysql_fetch_assoc($query1)) {
$userid=$row['id'];
$email=$row['email'];
}
there is no space between elseif lol and $owner[login] should have quotations like $owner['login'] as far as i can tell
lppa2004
Forum Newbie
Posts: 2
Joined: Wed Mar 03, 2010 3:53 pm

Re: This is driving me insane, please help

Post by lppa2004 »

well as soon as i saw the missing quotes i thought for sure that was the problem, something easily missed and would make the most sense as to why it wasnt working.. but after tidying up that bit of the code you pointed out and even using your mysql statement i still cant get it to work. Im at my wits end on this one, everytime i look at the code it works in theory but it just doesnt want to work properly when executed. I even considered rewriting the code but im not really sure i can make it work another way, my thought is to eliminate if pass = pass section and do inline checks of each field.. Id really like to uee what i got though since it makes the most sense in theory (and should work in practice)
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: This is driving me insane, please help

Post by scarface222 »

k add a } at the end of that section like so

Code: Select all

   if ($pass1 == $pass2) {
             $owner=mysql_fetch_array(mysql_query($db_name, "SELECT * FROM $tbl_member"));
    
             if ($login == $owner['login']){
            $error="10";
             }
           else if ($email == $owner['email']){
             $error="12";
            }
       
            else{$error="";}
}
You have to pay attention to what you are doing man, just read it over, I sometimes have the same problem and miss ridiculous errors. You are coding with really awkward if statement structure up ahead so just stay vigilant. AND READ THE ERROR MESSAGES BRO WHEN YOUR CODE DOES NOT WORK. People will not always help you every step of the way. You have to be more self-sufficient and just learn from practice.
Post Reply