Cory94bailly Posted May 16, 2010 Share Posted May 16, 2010 Yeah, I know.. I'm just stuck, I don't know how but I am! index.php <?php require("includes/includes.php"); ?> <html> <head> <title><?php echo $site_title; ?></title> </head> <body> Hi. </body> </html> includes.php <?php function includefile($filename) { if(file_exists($filename)) { include($filename); } else { die('<span style="color: red">Missing File: '.$filename.'</span>'); } } includefile("includes/config.php"); includefile("includes/functions.php"); includefile("includes/mysql_connect.php"); ?> config.php <?php $site_title = "Cory's Game"; //Name of site $mysql_connection_type = "2"; //1 = Normal,2 = Persistant (Persistant is only recommended if you know what you're doing!) $mysql_host = "localhost"; //MySQL Host Servers (Usually "localhost") $mysql_username = "root"; //MySQL Username $mysql_password = ""; //MySQL Password $mysql_database = "game"; //MySQL Database $mysql_prefix = ""; //Name added to the beginning of each table name (Example: "test" would be "test_users") ?> (I know, the comments aren't needed.. lol) But on 'index.php', the title is just this: <br /> <b>Notice</b>: Undefined variable: site_title in <b>C:\wamp\www\game\index.php</b> on line <b>6</b><br />: I honestly don't know why I'm getting that error unless the including/requiring messes up declaring variables? Thanks for any help (even the basics)! Link to comment https://forums.phpfreaks.com/topic/201931-stuck-with-declaring-variable/ Share on other sites More sharing options...
CodeMaster Posted May 16, 2010 Share Posted May 16, 2010 What is the ouput if you try this function instead? function includefile($filename) { try { include($filename); } catch (Exception $e) { die($e->getMessage()); } } Link to comment https://forums.phpfreaks.com/topic/201931-stuck-with-declaring-variable/#findComment-1059056 Share on other sites More sharing options...
corbin Posted May 16, 2010 Share Posted May 16, 2010 Look into function scope. A variable defined inside of a function does not exist outside of the function. As such, the variables defined in files included in a function, do not exist outside of a function. Link to comment https://forums.phpfreaks.com/topic/201931-stuck-with-declaring-variable/#findComment-1059065 Share on other sites More sharing options...
Cory94bailly Posted May 16, 2010 Author Share Posted May 16, 2010 Look into function scope. A variable defined inside of a function does not exist outside of the function. As such, the variables defined in files included in a function, do not exist outside of a function. Wow, I honestly don't know how I didn't realize that.. Oh well, that's what I get for coding at 1AM Thanks Link to comment https://forums.phpfreaks.com/topic/201931-stuck-with-declaring-variable/#findComment-1059195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.