Page 1 of 1

Small Problem!

Posted: Sun May 26, 2002 7:47 am
by Matto
This is quite a simple question, but me being new to PHP am finding it a little puzzling...

I have this...

Code: Select all

<?

if ($content == "code") &#123; code(); &#125;
else if ($content == "portfolio") &#123; portfolio(); &#125;
else if ($content == "communicate") &#123; communicate(); &#125;
else &#123; news(); &#125;

?>
Which links my pages together ?content=code to the code page, and whatnot.

The problem I have is when I go to index.php I get these warnings...
Warning: Undefined variable: content in C:\Inetpub\hosted\synister.org\index.php on line 63

Warning: Undefined variable: content in C:\Inetpub\hosted\synister.org\index.php on line 64

Warning: Undefined variable: content in C:\Inetpub\hosted\synister.org\index.php on line 65
Im not sure how to get rid of these warnings... I understand why I am getting them, but I cant seem to get rid of them. Any help would be apprectated.

Posted: Sun May 26, 2002 7:52 am
by MattF
You must have global thingy turned off, try this:

Code: Select all

&lt;?php
if(isset($_GET&#1111;"content"])) $_GET&#1111;"content"]();
else echo "No content specified";
?&gt;
That should work, bascially if there is a $content it tries to run a function of that name. It's by no means fool proof but it might work.

Posted: Sun May 26, 2002 11:23 am
by lc
Or you jsut add a

Code: Select all

if (empty($content))&#123;
$content = "nothing";
&#125;
Above the other code

that should do it

Basicly what I think I remember that happens in cases like yours is that php is setup to stop and show an error at every faulty line. It's a simple command that I am sure Jason has mentioned in a previous post.
Whilst your code isn't faulty really, it does halt it in case a variable is empty.

Posted: Mon May 27, 2002 5:58 am
by paulogv
Hello lc

If the other answears didn“t worked, try renaming the file from file.php to file.htm.

good luck

Posted: Mon May 27, 2002 8:25 am
by Tiimmy

Code: Select all

&lt;?php 

if (@$content == "code") {
    code(); 
} 
elseif (@$content == "portfolio") {
    portfolio();
} 
elseif (@$content == "communicate") {
    communicate();
} 
else {
    news();
} 

?&gt;
Just add a few simple @'s to your existing code, and no more problems. :twisted:

There's also a much easier method of doing that:

Code: Select all

&lt;?php

switch($content) {
    case 'code':
        code();
    break;
    case 'portfolio':
        portfolio();
    break;
    case 'communicate':
        communicate();
    break;
    default:
        news();
}

?&gt;
:D :lol: :D :lol: