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

Link to comment
Share on other sites

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.