Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Problem including files

  1. #1
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Problem including files

    Hi,

    I want to make a user authorization site and in order not to write much code, I created a php file with all the functions needed. OK till here. Now, when I include that file in other files with "include_once" function, it shows that message:

    Code:
    Fatal error: Call to undefined function doDB() in C:\PHP\AppServ\www\auth\members.php on line 10
    What can I do? Please help!!!!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try using require_once().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It shows excactly the same message.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is members.php the file you're including, or the file from which you are including?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    members.php is the file I'm including FROM.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    And we're sure the file is being included? Could you use an echo() in that include somewhere to make sure?

    It would help if you posted your code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, the file is included. I wrote an echo() in the file I wanted to include and it had an output.

    functions.php :
    Code:
    <?
    function doDB()
    {
    global $conn;
    $conn = mysql_connect("localhost", "costas", "thrilos") or die(mysql_error());
    mysql_select_db("userauth", $conn) or die(mysql_error());
    }
    
    function check($user, $pass)
    {
    global $conn, $sq_res;
    $sq = "select user_id from users where username = '$user' && enc = '$pass'";
    $sq_res = mysql_query($sq, $conn) or die(mysql_error());
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    </body>
    </html>
    members.php :
    Code:
    <?
    session_start();
    
    include_once("http://localhost/auth/functions.php");
    
    $username = $_POST[username];
    $password = $_POST[password];
    $enc = md5($password);
    
    
    doDB();
    check($username, $enc);
    
    if (mysql_num_rows($sq_res) == 1)
    {
    $valid_user = $username;
    $pass = $enc;
    $_SESSION[USER_LOGIN_VAR] = $valid_user;
    $_SESSION[USER_PASS_VAR] = $pass;
    // Some HTML Code
    }
    
    else
    {
    // Some HTML Code
    }
    
    ?>

  8. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    Hi Costas,

    I think your members.php and functions.php are residing in the same folder? If they are then instead of giving

    include_once ("http://localhost/auth/functions.php");

    give

    include_once ("functions.php");

    If these files are not residing in the same folder then check your php.ini file and go to the following section : "; Paths and Directories ;" in that section you have different sections for unix and windows where your can specify the folder path you want to check while include a file.

    If you are trying to include a file from a folder which is other than the specified folder then it will not consider that.

    You could've used relative path if you are working on a local machine

    It worked correctly for me to solve this problem, hope this will help you too.

    Regards

    Code Exploiter
    Last edited by codeexploiter; 08-23-2006 at 10:07 AM.

  9. #9
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll try it.

  10. #10
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks!!! It worked!

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
  •