PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > If working upside down
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
If working upside down

Réponse
 
LinkBack Outils de la discussion
Vieux 19/06/2008, 19h03   #1
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut If working upside down

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


  Réponse avec citation
Vieux 19/06/2008, 19h12   #2
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: If working upside down

Twayne wrote:

> -------------------------------
> <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"


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


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

You though your secrets were safe.
You were wrong.
-- From "Hackers" movie poster.
  Réponse avec citation
Vieux 19/06/2008, 19h30   #3
Twayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: If working upside down

> Twayne wrote:
>
>> -------------------------------
>> <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"

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


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.

Twayne


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h15.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21611 seconds with 11 queries