If working upside down

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Here's your chance to clobber a newbie good!  That's OK, I can take it
as long as it's relevant<g>.

In the following code snippet:
if(empty($_POST["pw"])) echo "pw is EMPTY<br><br/>"; // set error to 1
echo "pw is not empty<br/>";

echo "pw is " . ($_POST["pw"]) . "<br/>";

if(($_POST["n"])==($_POST["pw"])) echo "correct pw entered<br/>";  //set
error to 0
echo "Wrong password entered";

   I see the curly braces aren't there; they were earlier, but made no
The first "if" statement works fine and as expected:  IF a pw is
entered, it indicates it's not empty and displays it correctly in the
next line.

However, the second "if" statement is upside down.  If the pw is empty,
it says the correct pw was entered.  If ANYTHING has been typed into the
"pw" field, it says the pw is wrong, including when the correct pw is
filled in!
   It's more an "if empty" statement than it is a comparison of the two

The relevant part of the file providing the data is:
<form  method="post" action="nuCheckEntry.php">
$n=rand(0,9) . rand(0,99) * 2;
echo $n . "<br>";
<input type="text" name="pw">

<input type="submit" value="CONTINUE"


Screen output, with a correctly entered pw is:
pw is not empty
pw is 796 <=============== This IS what I entered for the pw.
Wrong password entered <====== but the correct pw was entered.  However,
                                                    entry draws this
same output.

As you can see, I've sprinkled echoes around so I can see a little of
what's happening.

I realize I've probably got my head up my ... so don't worry about being
painfully honest; that's what I'm here for as long as it's on topic.
This isn't a "real" project, it's just sandbox time to see if I know
what I think I know; which I'm not too sure of at the moment.  I seem to
be a lot better at fixing someone else's code (tut examples) than I am
at writing my own!! <G>

Specifically:  What's wrong with that 2nd "if" statement that makes it
seem to be working so wrongly?  Or is the problem elsewhere?



Re: If working upside down

Twayne wrote:

Quoted text here. Click to load it

You're not posting the value of 'n' in the form.

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

You though your secrets were safe.
You were wrong.
                         -- From "Hackers" movie poster.

Re: If working upside down

Quoted text here. Click to load it

GAKK!!!  I knew it'd be something stupid like that!  Time for a long
coffee break I think.
Thanks, I've been staring at that off & on since yesterday afternoon.


Site Timeline