dsartain Posted March 10, 2006 Share Posted March 10, 2006 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 More sharing options...
lessthanthree Posted March 10, 2006 Share Posted March 10, 2006 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 More sharing options...
mem0ri Posted March 10, 2006 Share Posted March 10, 2006 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. Link to comment Share on other sites More sharing options...
dsartain Posted March 10, 2006 Author Share Posted March 10, 2006 Yeah, the else statement was inside the while loop...how many years of coding and I missed that????? ah! Thanks Link to comment Share on other sites More sharing options...
Recommended Posts