Mackey18 Posted September 20, 2009 Share Posted September 20, 2009 Hello, me again, I am trying to do this statement, when I type in this code, it doesn't work: if ( $name == "Kevin" ) { echo( "Welcome, oh glorious leader!" ); } else { echo( "Welcome, $name!" ); } Can you teach me how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/ Share on other sites More sharing options...
Mackey18 Posted September 20, 2009 Author Share Posted September 20, 2009 What about this one aswell? if ( "Kevin" == $firstname and "Yank" == $lastname ) { echo( "Welcome, oh glorious leader!" ); } which goes with the form I put in: <FORM ACTION="welcome.php" METHOD=GET> First Name: <INPUT TYPE=TEXT NAME="firstname"><BR> Last Name: <INPUT TYPE=TEXT NAME="lastname"> <INPUT TYPE=SUBMIT VALUE="GO"> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921658 Share on other sites More sharing options...
Mark Baker Posted September 20, 2009 Share Posted September 20, 2009 If you're using a form to submit the values, then they're accessed withing the form action script using the $_GET or $_POST superglobal arrays (assuming tou have register globals disabled, as you should) if ( $_GET["firstname"] == "Kevin" ) { echo( "Welcome, oh glorious leader!" ); } else { echo( "Welcome, ".$_GET["firstname"]."!" ); } Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921663 Share on other sites More sharing options...
Mackey18 Posted September 20, 2009 Author Share Posted September 20, 2009 Thank you, it worked perfectly!! just a quick question, what does the "!" mean near the end here: else { echo( "Welcome, ".$_GET["firstname"]."!" ); } Thanks again, you're a life saver! Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921667 Share on other sites More sharing options...
Mackey18 Posted September 20, 2009 Author Share Posted September 20, 2009 Oh sorry, that is the ! after the firstname isn't it!? Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921669 Share on other sites More sharing options...
dezkit Posted September 20, 2009 Share Posted September 20, 2009 Yeah. Quote Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.