Jump to content

Included variables are all blank.


Nuggit

Recommended Posts

This is the first part of myblog.php, which is the page you see in the browser.

<?php 
require("/home/www/htdocs/master.php"); //functions are in here

$u = "test"; //username
$htitle = "Test blog!"; //for <title>

//includes
dbcon(); //connect to database
blog($u);

// START PAGE
echo $welcomemessage;

Functions are in master.php.

It calls function dbcon, which logs me into MySQL and selects the database.

It calls function blog:

function blog($u) {
//not using $u for anything yet.
require($path."blog/vars.php");
require($path."blog/head.php");
}

Vars defines stuff needed for the blog, Head is the header, with <html>, <head>, etc.

 

$welcomemessage is defined in vars.php, but it doesn't show anything when I echo it in myblog.php. I went into vars.php and made it echo in there, and it worked, so it is defined correctly and the file is included, but for some reason the variable goes blank by the time I get back to myblog.php. It's the same with all the arrays I defined in there too.

 

What's going on? :(

 

I am using:

PHP 5.2.3-1ubuntu6

Ubuntu 7.10

Link to comment
https://forums.phpfreaks.com/topic/78988-included-variables-are-all-blank/
Share on other sites

Check out scope, its a common issue with this, you can't scope UP basically

Oh wow.

 

I tried it without using that handy blog() function and directly requiring them instead, and now it seems to work.

 

I just need to avoid doing that with functions, then?

 

edit: or, I could still use the function if I make it &blog()? I'm reading about references now.

Thanks guys.

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.