SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My include file won't work

    Hi,

    I have written a config.php file that houses global constants
    that I continually call throughout my program. The config.php file
    resides in the same directory as all my other php files.

    ** Contents of my config.php file
    <?php
    define('DB_NAME', 'athlete322');
    define('DB_USER', 'athlete55');
    define('DB_PWD', 'registration2008');
    ?>

    ** Contents of my open database file
    odbc_close_all();
    require_once "config.php";

    $iConnect = odbc_connect ($DB_NAME, $DB_USER, $DB_PWD);

    if (! $iConnect)
    {
    DisplayMessageToUser("Unable to connect to database.<br/>");
    exit();
    }

    I am getting the following error.
    Undefined variable: DB_NAME
    Undefined variable: DB_USER,
    Undefined variable: DB_PWD

    What have I done wrong?


    Thanks.

  2. #2
    SitePoint Zealot
    Join Date
    May 2007
    Location
    West Midlands, UK
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have included the file wrong.

    Undefined means the constant hasn't yet been defined. If you include the script correctly then you wouldn't get undefined.

    Make sure you include the script at the top of the page somewhere.

    EDIT:

    Sorry, I just read it says Undefined Variable.

    You can only use defined() with CONSTANTS and not variables. How did you define your origional CONSTANTS? Did you use define(); ?

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Jhyalipati,Chapagaun-9, Lalitpur, Bagmati, Nepal
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $iConnect odbc_connect (DB_NAMEDB_USERDB_PWD); 
    Simply Sajan

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, you don't put $ in front of constants.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •