The_Holy_One Posted May 23, 2006 Share Posted May 23, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/10247-declare-a-variable-correctly/ Share on other sites More sharing options...
zq29 Posted May 23, 2006 Share Posted May 23, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10247-declare-a-variable-correctly/#findComment-38189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.