my else statement is not executing it returns a black page.

while($results = mysql_fetch_array($user_name))
         {
			if ($results['email'] == $Entered_UserName && $results['password'] == $Entered_PassWord)
         		echo 'working';
			else
         		echo 'not working';
		}

Recommended Answers

All 4 Replies

my else statement is not executing it returns a black page.

while($results = mysql_fetch_array($user_name))
         {
			if ($results['email'] == $Entered_UserName && $results['password'] == $Entered_PassWord)
         		echo 'working';
			else
         		echo 'not working';
		}

should be

<?php
   while($results = mysql_fetch_array($user_name)) {
      if ($results['email'] == $Entered_UserName && $results['password'] == $Entered_PassWord) {
         echo 'its working';
      } else {
         echo 'its not working';
   }
?>

you missed the {} on the 2nd if statement

Technically, it doesn't matter if you have only 1 line statement after a condition. ie.,

<?php
$x = 1;
if($x == 1) 
    echo "$x is valid.";
else 
    echo "$x is invalid";
?>

This will not work if you have more than 2 statements in your condition.
Btw, its not a good practice to miss { } for your conditions.

my else statement is not executing it returns a black page.

while($results = mysql_fetch_array($user_name))
         {
			if ($results['email'] == $Entered_UserName && $results['password'] == $Entered_PassWord)
         		echo 'working';
			else
         		echo 'not working';
		}

Check your variable name, that are properly used or check whether the conditional variable assigns the correct information from the user.

In that case if the missng {} is not the issue, you may want to check that $user_name contains the relevant information. try a print_r($user_name) before you execute the mentioned code and see if it contains the info you are looking for. Work backwards from there

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.