complete newbie using if($option == "1"){ ...... outputs blank page

Hi there, I have a major headache trying to resolve why this won’t work -

I have a menu system which calls optional html pages for example: [php]<?php if($option == "1"){ include('mentime.htm'); ?>[/php]. If I try to bring up the page from my online testing site the header and footer text show just fine but where the html file is supposed to be just comes up a complete blank.

If I try to run the php file through localhost apache server I get Notice: Undefined variable:Option…line 22.

The php code posted above is line 22.

Anybody have any pointers as to where the problem may be?

You’re missing closing }

Sorry, I forgot to copy and paste the next line of code. The closing[php]}[/php] is on the next line down.

A little more background : we currently have a site that uses this php file and it works perfect.
As the new webmaster I have been tasked with giving the site a new look. Since the file is working already I decided to use it in its current format as the basis for the new menu system. I have amended the html links within the php file to reflect the new file names. Now it just won’t work. I use Dreamweaver to edit and upload.

If you need any further info please don’t hesitate to ask, thank you for your response so far.

And where the variable $option comes from? As a parameter from query string? You may need to use $_REQUEST[‘option’] instead, and check if this element is set using isset() function (to avoid notice error message).
Like this:
[php]<?php if(isset($_REQUEST['option']) and $_REQUEST['option'] == "1"){ include('mentime.htm'); } ?>[/php]

Also where the include file mentime.htm is located? In the same directory as php script?

I have created a flash menu with a button called Timetable which is linked to worlds.php like this :

"http://www................/worlds.php?option=1"

Option 1 in worlds.php reads like this:

[php]if($option == “1”){
include (‘mentime.htm’);
}[/php]

and mentime.htm is in the root directory. The worlds.php file also calls header.htm which is also located in the root.
I am starting to think that maybe the variable $option is somehow set through the javascript menu (which is on the current working site) if that’s possible.

I may be in too deep for my level of knowledge of PHP.

Did you try to replace $option with $_REQUEST[‘option’], as shown in the post above?
The $option would be set if you have register_globals = On in your php.ini (but this is deprecated and by default this setting is turned Off in latest PHP releases)

Sorry for the delay in responding, been trying to get some sleep.

I tried the $request suggestion you made, but, out of sheer tiredness, I used copy and paste. Unfortunately it didn’t work, but after having had some sleep, I realised something was missing. I had not copied the whole line and had missed out the ; } at the end.

I am more awake now and have redone the line and whoopee it seems to work. I can now click on the menu button and it shows me the correct content. I can only assume that the register_globals is on with our current hosting package.

Please don’t underestimate how much I appreciate your help and input. THANK YOU SO MUCH. I will go and test the rest of the menu now.

If necessary can I request further assistance without causing offence?

You’re welcome!

Sure, feel free to post your questions. This is a ‘php help’ forum after all :slight_smile:

;D Just to let you know my menu now works perfectly. Thank you so much for all your help.

I will no doubt become a regular visitor here as I expand my knowledge of PHP.

Out of interest, does the $_REQUEST etc. define the variable or does it switch something on at the hosting side?

$_REQUEST is one of predefined variables in PHP. This is an array that contains all data from other predefined variables - $_POST, $_GET, $_COOKIE.

In your case you can use just $_GET array instead of $_REQUEST. But sometime it is more convenient to use $_REQUEST, instead of checking if variable came from $_GET or from $_POST.

When you’re debugging your php code, you can always dump these predefined arrays to check what data is passed to the script, and from where. Like this:
[php]<?php
echo ‘

POST:

’;
echo ‘
’;
var_dump($_POST);
echo ‘
’;

echo ‘

GET:

’;
echo ‘
’;
var_dump($_GET);
echo ‘
’;

echo ‘

COOKIE:

’;
echo ‘
’;
var_dump($_COOKIE);
echo ‘
’;
?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service