Jump to content


Photo

Declare a Variable correctly...


  • Please log in to reply
1 reply to this topic

#1 The_Holy_One

The_Holy_One
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 May 2006 - 09:27 AM

<?php
    
    echo "<div class=\"content\">\n";
    echo "    <div class=\"title\">";
    echo $titel.":";
    echo "</div>\n";
    echo "    <div class=\"text\">\n";

    if(isset($_GET['game'])) {
        
        $titel = $_GET['game'];
        // $content = "";
                
        if(isset($_GET['server'])) {
        
            $titel = $_GET['game']." ".$_GET['server'];
            // $content = "";
        
            if(isset($_GET['amount'])) {
            
            $titel = $_GET['game']." ".$_GET['server']." ".$_GET['amount'];
            // $content = "";        
            }
        } 
    } else {
        $titel = "News";
        // $content = include "news.php";
    }
    
    // echo $content;

    echo "</div></div>";
    echo "</body>\n";
    echo "</html>\n";
?>

ERROR MESSAGE: Notice: Undefined variable: titel in /var/www/web49/html/php/index.php on line 5 :

PROBLEM DESCRIPTION:
If someone visit my Page and click a Link for example: "index.php?game=123" the titel which will be shown at different places of the page should be "123" but i cant get the information backway, so i have no idea how to work around this problem. Also i have the problem that "$content = include "news.php";" doesnt work, if i echo $content then it will only show the TEXT "include "news.php"" and dont include the page it self.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 23 May 2006 - 10:38 AM

You're calling $titel before it has been defined, you need to create, or assign a variable a value before you can use it.

You can't assign an include to a variable either. You could set your variable to a value and then decide what to display depending on that variable.

<?php    
if(isset($_GET['game'])) {
    $titel = $_GET['game'];
    // $content = "";
                
    if(isset($_GET['server'])) {
        $titel = $_GET['game']." ".$_GET['server'];
        // $content = "";
        
        if(isset($_GET['amount'])) {
            $titel = $_GET['game']." ".$_GET['server']." ".$_GET['amount'];
            // $content = "";        
        }
    }
} else {
    $titel = "News";
    $content = "news.php";
}
    
if(!empty($content)) include $content;

echo "<div class=\"content\">\n";
echo "    <div class=\"title\">";
echo $titel.":";
echo "</div>\n";
echo "    <div class=\"text\">\n";
echo "</div></div>";
echo "</body>\n";
echo "</html>\n";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users