Jump to content

[SOLVED] if statement


geroido

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/
Share on other sites


<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?

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589491
Share on other sites

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'];

        }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589498
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589500
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589505
Share on other sites

<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.

Link to comment
https://forums.phpfreaks.com/topic/114645-solved-if-statement/#findComment-589513
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.