-2

I have made a login form using PHP and MySQL. However, I am running into an error when I type in the wrong login info.

<?php

    while($row = mysql_fetch_array($result))
    {
    if($result)
      {
       header('Location: supplementsstore.php');
      }
    else
      {
        header('Location: logon.php');
      }
    }

?>

The if works as it's supposed to, but it does not do the else statement. I have tried changing else to !$result but that didn't work either.

8
  • 3
    "i am running in to an error" - Being? Take your pick of 1001 possible reasons. Totally unclear what you're asking. Commented Apr 3, 2015 at 18:15
  • 1
    Why are you doing if($result)? Commented Apr 3, 2015 at 18:15
  • What is $result we need more details Commented Apr 3, 2015 at 18:16
  • Whatever your mistake is, the exit is missing for guarantee. Commented Apr 3, 2015 at 18:19
  • If you are inside that loop, that already means if($result) is true, so your else statement is unreachable. Commented Apr 3, 2015 at 18:19

2 Answers 2

2

If if($result) were to evaluate to false the while loop would never be entered.

So try:

if( count($row) > 0 ) 

rather than

if($result){}
Sign up to request clarification or add additional context in comments.

1 Comment

I'd never take that stab in the dark, even with the biggest and longest knife around. But, you may be right. Let's see what the OP has to say ;-) Could be a lucky shiv.
0
if($row = mysql_fetch_array($result))
{
header('Location: supplementsstore.php');
}
else
{
header('Location: logon.php');
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.