Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
there seems to be a logical error with regards to my PHP if statements everything looks pretty fine to me please help. Im developing a USSD Application using PHP.
The program goes into the first if statement, i input *234# then it doesn't prompt for "please enter pin" it just jumps into invalid pin without giving me a chance to enter the '9876' pin. Sorry for the bad coding i'm new to php development
Expected Program flow:
1. user input: *234#
2. Please enter pin
3. user input: 9876
3. Welcome Mr smith

PHP
$msg = $input["message"];

if ($msg == "*234#") {
    $data["message"] = "Please enter pin";

    $pass = $input["message"];

    if ($pass == 9876) {
        $data["message"] = "Welcome Mr. Smith";
    } else {

        $data["message"] = "Incorrect password, please try again";

    }
} else {
    $data["message"] = "invalid code, please try again";
}
Posted
Updated 12-Jul-13 21:42pm
v3
Comments
enhzflep 12-Jul-13 19:57pm    
What's your question? What's the expected and observed behaviour?
Sergey Alexandrovich Kryukov 12-Jul-13 20:43pm    
This code is bad in style, but it cannot be "correct" or "wrong" by itself.
It all makes no sense at all unless you tell us what you wanted to achieve, what happens instead and why do you feel it's wrong.
—SA
NhlanhlaK 13-Jul-13 3:40am    
i have improved the question, hope it helped
Sergey Alexandrovich Kryukov 14-Jul-13 0:10am    
Much better. Thank you for the clarification of the question. I hope you got an answer. If not, you can comment on the answer (and perhaps reply to this comment) with your follow-up question.
Cheers,
—SA

1 solution

you didn't "echo" the variables used, that's why there is no display result.

PHP
$msg = "*234#";

if ($msg == "*234#") {
    $data["message"] = "Please enter pin";

    //echo $data["message"];

    $pass = 9876;

    if ($pass == 9876) {
        $data["message"] = "Welcome Mr. Smith";

       // echo $data["message"];
    } else {

        $data["message"] = "Incorrect password, please try again";

       // echo $data["message"];

    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900