Jump to content

Archived

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

dsartain

Else Staatement not working

Recommended Posts

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.

[code]
$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>[/code]

Share this post


Link to post
Share on other sites
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:
[code]
else
{
$query_result ="Thanks for registering!";
/*
$runquery = mysql_query($query,$dbconn);
if (!$runquery) {echo "Query Failed"; } else {echo "Thank you for registering!";}
*/
}
}
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Yeah, the else statement was inside the while loop...how many years of coding and I missed that????? ah! Thanks

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.