Jump to content

Declare a Variable correctly...


The_Holy_One

Recommended Posts

[code]<?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";
?>
[/code]

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

[b]PROBLEM DESCRIPTION:[/b]
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.
Link to comment
Share on other sites

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.

[code]<?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";
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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