PHP Guru Needed (Passing variables)

Discussion in 'PHP' started by zeldaze, Sep 20, 2008.

  1. #1
    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');
    ?>
    PHP:
    Application_top.php looks like this:
    <?php
    session_start();
    require('config.php');
    ?>
    
    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 :)
     
    zeldaze, Sep 20, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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');
    PHP:
    and then use
    <title><?php echo BOARDNAME; ?></title>
    PHP:
    in your file
     
    JAY6390, Sep 20, 2008 IP
  3. zeldaze

    zeldaze Active Member

    Messages:
    311
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I tried using define and it doesn't work either. Now I just get BOARDNAME as the title.
     
    zeldaze, Sep 20, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is this on localhost or a server?
     
    JAY6390, Sep 20, 2008 IP
  5. zeldaze

    zeldaze Active Member

    Messages:
    311
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Localhost, would that affect anything?
     
    zeldaze, Sep 20, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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
     
    JAY6390, Sep 20, 2008 IP
  7. zeldaze

    zeldaze Active Member

    Messages:
    311
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Ok - I tested it live and it works. Thanks a lot!
     
    zeldaze, Sep 20, 2008 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you are still having probs with it locally, and you are using XAMPP then try WAMP instead, and vice versa
     
    JAY6390, Sep 20, 2008 IP
  9. classic

    classic Peon

    Messages:
    96
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I highly recommend using OO style as if your project starts becoming complex you will just say PHP sucks
     
    classic, Sep 20, 2008 IP