Jump to content

Else Staatement not working


dsartain

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]
Link to comment
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]
Link to comment
Share on other sites

Guest
This topic is now 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.