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? 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> 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"]."!" ); } 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! 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!? 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. Link to comment https://forums.phpfreaks.com/topic/174887-the-if-else-statement/#findComment-921757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.