Small Problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Matto
Forum Newbie
Posts: 1
Joined: Sun May 26, 2002 7:47 am
Location: Australia
Contact:

Small Problem!

Post 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.
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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.
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post 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.
paulogv
Forum Newbie
Posts: 2
Joined: Mon May 27, 2002 5:58 am
Contact:

Post by paulogv »

Hello lc

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

good luck
Tiimmy
Forum Commoner
Posts: 38
Joined: Sat Apr 27, 2002 1:56 am
Location: Australia
Contact:

Post 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:
Post Reply