Watch Anime - to-reuse.com - Wordpress Themes - Indian television shows news - Wordpress Themes

PDA

View Full Version : PHP Guru Needed (Passing variables)


zeldaze
Sep 20th 2008, 5:57 am
Hi,

I have been fiddling around with this situation for ages now and I can't seem to find a solution. I will do my best to provide the details in the best way.

Say I have a file, index.php, that looks like this:
<?php
require('application_top.php');
require('header.php');
?>

Application_top.php looks like this:
<?php
session_start();
require('config.php');
?>

Config.php simply holds my database connection information.

And lastly header.php holds some of the header for my template in a system I am developing.

Now, I have two problems. The first one is this. Say that config.php or application_top.php held some defined variables, how can I transfer them to header.php? For example, I have $boardname defined in config.php, and in header.php I have <title><?php echo $boardname; ?></title>. It is not sending any value for the variable.

My next problem is quite weird and only happened when I started meddling with my system. Basically, config.php has all my database information and connection and config.php is called in application_top.php as previously shown. My problem is that if I include application_top.php in a file and I run a MySQL query in that file, then I get errors saying that I am not connected to the database etc. This problem never used to happen but now all of a sudden I have to include config.php directly into a file if I want to query a database. Why is this? It didn't happen before and now it does.

Any help will be appreciated.

Thanks :)

JAY6390
Sep 20th 2008, 6:09 am
I see no reason why you are having trouble with your first problem. It should work exactly as you have said. In your config file you might want to change the $boardname to
define('BOARDNAME','board name value here');
and then use
<title><?php echo BOARDNAME; ?></title> in your file

zeldaze
Sep 20th 2008, 6:30 am
I tried using define and it doesn't work either. Now I just get BOARDNAME as the title.

JAY6390
Sep 20th 2008, 6:32 am
Is this on localhost or a server?

zeldaze
Sep 20th 2008, 6:32 am
Localhost, would that affect anything?

JAY6390
Sep 20th 2008, 6:59 am
It all depends on whether you have your server set up correctly. If you have a web server test it on there to see if it works there

zeldaze
Sep 20th 2008, 7:07 am
Ok - I tested it live and it works. Thanks a lot!

JAY6390
Sep 20th 2008, 7:15 am
If you are still having probs with it locally, and you are using XAMPP then try WAMP instead, and vice versa

classic
Sep 20th 2008, 3:39 pm
I highly recommend using OO style as if your project starts becoming complex you will just say PHP sucks