Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
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
 
$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 12-Jul-13 13:13pm
Edited 12-Jul-13 22:42pm
v3
Comments
enhzflep at 12-Jul-13 19:57pm
   
What's your question? What's the expected and observed behaviour?
Sergey Alexandrovich Kryukov at 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 at 13-Jul-13 3:40am
   
i have improved the question, hope it helped
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you didn't "echo" the variables used, that's why there is no display result.
 
$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"];

    }
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100