Page 1 of 1

PHP + fatal error

Posted: Fri May 09, 2008 3:37 am
by anamika12345
hi ,
i got Fatal error : call to undefined function get_fname() on C:\apache\apache2\htdocs\Abc\Myproject\info.php on line no 96;

can any won help to to solve the error : :(

Re: PHP + fatal error

Posted: Fri May 09, 2008 3:41 am
by EverLearning
Post some code. We're not clairvoyant(atleast most of us aren't ;))

Re: PHP + fatal error

Posted: Fri May 09, 2008 6:21 am
by anamika12345
i am having,
Abc (main directory under htdocs)
|_ Myprojects(folder)-info.php(main file)
|_ MyWebsite(folder) - functions.inc.php(file)
- database.inc.php (File)

In info.php i am using folowing code
<?php

include("../../MyWebsite/database.inc.php");
include("../../MyWebsite/functions.inc.php");

?>
<html>
<body>
<table>
<tr>

<td valign="top" align="center">
<td valign="top"><? echo xyz->create_date?></td>
<td valign="top"><?=get_fname(xyz->u_id); ?></td>
<td align="center" width="120" valign="top"></td>

</tr>
</body>
</html>

</body>
</html>


An in Mywesite/functions.inc.php i am using

<?
function get_fname($uid)
{
$query1 = "select name,add from profile where uid='$uid'";
$result = mysql_query($query1);
$rec = mysql_fetch_array($result);
echo $rec['name'];


}
function 2
{


}
function 3
{

}

Re: PHP + fatal error

Posted: Fri May 09, 2008 6:39 am
by EverLearning
If I understood your file structure correctly your includes should be(I couldn't tell if database.inc.php was in MyWebsite folder or in one folder up)

Code: Select all

include("../database.inc.php");
include("../MyWebsite/functions.inc.php");
Use require instead of include.

Also it is a better practice to use absolute paths. For example, define a constant e.g . BASE_PATH in a file that is included everywhere(e.g. config.inc.php), and use it in all you require and include statements

Code: Select all

require(BASE_PATH . 'MyWebsite/functions.inc.php');

Re: PHP + fatal error

Posted: Fri May 09, 2008 6:51 am
by anamika12345
Sorrrryyyyyyyyyyy,the file structure is like


Abc (main directory under htdocs)
|_ Myprojects(folder)
| |_Myfiles(folder)
| -info.php(main file)
|_ MyWebsite(folder)
- functions.inc.php(file)
- database.inc.php (File)

I am sorry for wrong information .I tried to set up the base path but didi not got success .]
When a put
include(../../MyWebsite/function.inc.php)
i got the rest opf the result on my page like current date ,but it didnot show the user name s only.
and when i put
include(http://localhost/.....................)
whole path i got fatal error .
i didnt get where i am going wrong????

Re: PHP + fatal error

Posted: Fri May 09, 2008 7:27 am
by DeFacto
1. are you sure you did like EverLearning showed you?

Code: Select all

 
require(BASE_PATH . 'MyWebsite/functions.inc.php');
 
2. could you post an image of your website tree?

Re: PHP + fatal error

Posted: Sat May 10, 2008 1:59 am
by RobertGonzalez
Which file does the missing function live in? Once you know that, include that file.

Re: PHP + fatal error

Posted: Sat May 10, 2008 2:19 am
by EverLearning
Just spoted this. In functions.inc.php you're using short tags <? ?> instead of full <?php ?> tags. If you're on PHP5 short_open_tag option is off by default(its on in PHP4, but can be disabled).

If this option is off, then your functions.inc.php isn't parsed at all, and thats why you get
anamika12345 wrote:Fatal error : call to undefined function get_fname()
Always use the <?php ?>. I guess your filepaths were OK.