Jump to content

Stuck with declaring variable


Cory94bailly

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

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