geroido Posted July 14, 2008 Share Posted July 14, 2008 Hi Can anyone help me with this. I'm new to PHP. I can't get the following if/else statment to work. I think it's a syntax error but can't find it. <div class="meta"> if ($_SESSION['userchoice'] = 'order') || ($_SESSION['userchoice'] = 'book') || ($_SESSION['userchoice'] = 'drink') { <?include("usermap.php");?> } else { <?print $_SESSION['userchoice']?> } </div> All I want at the moment is to include the usermap.php if the conditions are true or simply print the contents of the variable if not true. Currently it just print the code on the page but doesn't do anything. thanks Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/ Share on other sites More sharing options...
waynew Posted July 14, 2008 Share Posted July 14, 2008 <div class="meta"> <?php if (($_SESSION['userchoice'] == 'order') || ($_SESSION['userchoice'] == 'book') || ($_SESSION['userchoice'] == 'drink')) { include("usermap.php"); } else { print $_SESSION['userchoice']; } ?> </div> Yours was: <div class="meta"> if ($_SESSION['userchoice'] = 'order') || ($_SESSION['userchoice'] = 'book') || ($_SESSION['userchoice'] = 'drink') { <?include("usermap.php");?> } else { <?print $_SESSION['userchoice']?> } </div> See the difference? Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589491 Share on other sites More sharing options...
paul2463 Posted July 14, 2008 Share Posted July 14, 2008 = assigns a value to a variable... == checks to see if two values are equal === checks to see if two things are exactly the same value and type in an if statement you are checking for equality and not assignation - use == not = HTH Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589492 Share on other sites More sharing options...
waynew Posted July 14, 2008 Share Posted July 14, 2008 The reason that it printed the code was because you didn't enclose the if statement inside a php bracket which meant that it was taken as plain text. You also used = instead of == when comparing and your brackets were all messed up. Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589494 Share on other sites More sharing options...
geroido Posted July 14, 2008 Author Share Posted July 14, 2008 Hi Waynewex Thanks for the help but all I'm getting now is the usemap page when I select 'drink'. I don't get it if I select 'book' or 'food'. I have four buttons on my page labelled 'drink', 'food', 'book' and 'view'. If the user select book, food or drink, I want the usemap page to be included. If they select 'view' then I just want that word to appear. Any ideas? <?php if (($_SESSION['userchoice'] == 'order') || ($_SESSION['userchoice'] == 'book') || ($_SESSION['userchoice'] == 'drink')) { include("usermap.php"); } else { print $_SESSION['userchoice']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589498 Share on other sites More sharing options...
waynew Posted July 14, 2008 Share Posted July 14, 2008 Hi Waynewex Thanks for the help but all I'm getting now is the usemap page when I select 'drink'. I don't get it if I select 'book' or 'food'. I have four buttons on my page labelled 'drink', 'food', 'book' and 'view'. If the user select book, food or drink, I want the usemap page to be included. If they select 'view' then I just want that word to appear. Any ideas? Could you post the buttons? Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589500 Share on other sites More sharing options...
trq Posted July 14, 2008 Share Posted July 14, 2008 Where do you define $_SESSION['userchoice'] ? Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589501 Share on other sites More sharing options...
geroido Posted July 14, 2008 Author Share Posted July 14, 2008 thanks. Here's the code for my buttons <form id="form1" method="post" action="userChoice.php"> <fieldset> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="food" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="drink" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="Book" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="View" /> </fieldset> </form> Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589505 Share on other sites More sharing options...
waynew Posted July 14, 2008 Share Posted July 14, 2008 <form id="form1" method="post" action="userChoice.php"> <fieldset> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="food" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="drink" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="book" /> <BR><input id="inputsubmit1" type="submit" name="usechoice" value="view" /> </fieldset> </form> Try that. Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589513 Share on other sites More sharing options...
waynew Posted July 14, 2008 Share Posted July 14, 2008 Also, can we see your post values? How they arrive on the page? Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589515 Share on other sites More sharing options...
geroido Posted July 14, 2008 Author Share Posted July 14, 2008 Thanks guys. I got it. I just wasn't paying attention. I was using the wrong word in the condition that I had assigned to the value of the submit button. Feel silly now Quote Link to comment https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589519 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.