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:
--------------------------------
<?php
if(empty($_POST["pw"])) echo "pw is EMPTY<br><br/>"; // set error to 1
else
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
else
echo "Wrong password entered";
?>
--------------------------------
I see the curly braces aren't there; they were earlier, but made no
difference.
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
variables.
The relevant part of the file providing the data is:
-------------------------------
<form method="post" action="nuCheckEntry.php">
<hr><br>
<?php
$n=rand(0,9) . rand(0,99) * 2;
echo $n . "<br>";
?>
<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,
ANY
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?
TIA,
Twayne