Jump to content

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

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.