simcoweb Posted June 13, 2006 Share Posted June 13, 2006 Ok, I've already announced that i'm a newb. JUST learning PHP and going through literally dozens of tutorials and moving along. However, like I say to my proctologist... be gentle! :)Here's the scoop. I've created a simple form in order to practice the if/else routines and experiment with the output. I already created a simulated order form and got that working without a hitch while swapping displayed messages depending upon how many of each item they ordered and also what their total number of items ordered. Worked great. But! Now what I tried was to compare text input and 'if' it meets a certain name (in this case a game) then it would display one message and if they entered something else it would display a different message.here's the code for the form:<html><head></head><body><form name="shanetest" action="shanetest.php"><font face="Verdana" size="2">Enter Your Favorite Game</font><br><input type="text" name="gamename" size="20"><p><font face="Verdana" size="2"><b>Your Gamer Tag</b></font><br><input type="text" name="gamertag" size="20"><p><input type="submit" name="submitinfo" value="Submit yo stuff" style="cursor:pointer"></form></body></html>And my code for the 'shanetest.php' file:<?php // First we create some variables$gamertag = $_POST['gamertag'];$gamename = $_POST['gamename'];// Now we process the information if ( $gamename == "halo" ) {echo "You are the bomb, baby!<p>";} else {echo "you are a LOSER!<p>";}if ( $gamertag == "rockmetal" ) {echo "That rocks, dude!<p>";} else {echo "Why would you play that lame game?";} ?> Now, all I get is the 'false' statements displayed. Even if you type in the proper entries of 'halo' and 'rockmetal' it won't display the 'if' true statements.Once again, logically it should work. Code wise I must be missing something or trying to produce something that PHP needs additional info or a different operator. I see lots of examples of this but none that showed the variables being populated by a form input and then being compared in an 'if' statement. Can someone point me in the right direction? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/ Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 Try this[code]<?php // First we create some variables$gamertag = $_POST['gamertag'];$gamename = $_POST['gamename'];// Now we process the information if ( ! $gamename == "halo" ) {echo "You are the bomb, baby!<p>";} else {echo "you are a LOSER!<p>";}if (! $gamertag == "rockmetal" ) {echo "That rocks, dude!<p>";} else {echo "Why would you play that lame game?";} ?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/#findComment-44854 Share on other sites More sharing options...
litebearer Posted June 13, 2006 Share Posted June 13, 2006 Sorry couldn't resist....When asked by his patient why he used two fingers, the proctologist replied..."I always like to get a second opinion" Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/#findComment-44856 Share on other sites More sharing options...
simcoweb Posted June 13, 2006 Author Share Posted June 13, 2006 Hey..thanks for the quick reply. Ok, tried that. I see you added some '!'characters in there. I also notice that their position in the statement is a little different but I don't think that makes a difference... does it?Here's what happened when I made the changes. The 'true' statements printed but when entering the 'false' data (anything but what the variables hold true at which is 'halo' and 'rockmetal') then it still displays the 'true' statements. I type in anything in the two form fields and it displays the 'true' text. It's not parsing the 'false' statements.So, adding those '!' now makes the true happen no matter what.Just make sure that when your at the proctologists that while feeling the probe you don't also notice both his hands on your shoulders ;) Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/#findComment-44859 Share on other sites More sharing options...
Barand Posted June 13, 2006 Share Posted June 13, 2006 Uou are referring to $_POST variables but the default method for forms is GET. Specify form method as "POST" Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/#findComment-44868 Share on other sites More sharing options...
simcoweb Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo(post=383111:date=Jun 13 2006, 12:57 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 13 2006, 12:57 AM) [snapback]383111[/snapback][/div][div class=\'quotemain\'][!--quotec--]Uou are referring to $_POST variables but the default method for forms is GET. Specify form method as "POST"[/quote]DOHHHH! Wow, can't believe I missed that. Ok, i'll post back with the results. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/11837-total-newb-needs-help-with-ifelse/#findComment-44904 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.