View Full Version : Problem including files
costas
08-22-2006, 02:04 PM
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:
Fatal error: Call to undefined function doDB() in C:\PHP\AppServ\www\auth\members.php on line 10
What can I do? Please help!!!!:( :mad:
Try using require_once().
costas
08-22-2006, 03:07 PM
It shows excactly the same message.
Is members.php the file you're including, or the file from which you are including?
costas
08-22-2006, 05:31 PM
members.php is the file I'm including FROM.
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.
costas
08-23-2006, 08:53 AM
Yes, the file is included. I wrote an echo() in the file I wanted to include and it had an output.
functions.php :
<?
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 :
<?
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
}
?>
codeexploiter
08-23-2006, 10:01 AM
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
costas
08-23-2006, 10:11 AM
I'll try it.
costas
08-23-2006, 10:13 AM
Thanks!!! It worked!
codeexploiter
08-23-2006, 10:16 AM
Hi costas,
Welcome man
Regards
Code Exploiter
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.