Jump to content


Photo

Else Staatement not working


  • This topic is locked This topic is locked
3 replies to this topic

#1 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 10 March 2006 - 07:50 PM

I'm building a fairly standard registration form. I've got a couple of if statements to make sure that the username hasn't already been taken and the email address hasn't been registered already. The If and elseif statements work fine, but I get no output for the else statement at all. Please help me here, this is my last step to finish this.

$q="SELECT * FROM teresa_votes_test WHERE username='$username' OR email='$email'";
$res=mysql_query($q);


$query = "INSERT INTO `teresa_votes_test`     VALUES('','$name','$username','$password','$email', '')";

while($row = mysql_fetch_array($res))
{

    if($row['username']==$username)
    {
         echo $row['name']. " ". $row['username']. " ". $row['email']. " ".  "<br />";
         $query_result = "That username has already been taken, please choose another <br />";
    }
    elseif($row['email']==$email)
    {
         echo $row['name']. " ". $row['username']. " ". $row['email']. " ".  "<br />";
         $query_result = "You have already registered with us <br />";
    }
    
    else
    {
             $query_result ="Thanks for registering!";
            /*
            $runquery = mysql_query($query,$dbconn);
            if (!$runquery) {echo "Query Failed"; } else {echo "Thank you for registering!";}
            */
    }
}


<body>
<?php echo $query_result ?>
</body>


#2 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 10 March 2006 - 07:55 PM

this may sound sill and it probably isn't what's causing your problem (only had a very quick glance), but are you aware any part of the else part of that code is commented out, and consequently won't do anything at all.

Here:
else
{
$query_result ="Thanks for registering!";
/*
$runquery = mysql_query($query,$dbconn);
if (!$runquery) {echo "Query Failed"; } else {echo "Thank you for registering!";}
*/
}
}

call me a safe bet, i'm betting i'm not

#3 mem0ri

mem0ri
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 10 March 2006 - 08:02 PM

Just a quick look...but it appears that your "else" statement is nested within your while statement...which means it will only run if you get a return row from the database...

...that would be your problem.

#4 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 10 March 2006 - 09:19 PM

Yeah, the else statement was inside the while loop...how many years of coding and I missed that????? ah! Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users