PHP + fatal error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anamika12345
Forum Newbie
Posts: 5
Joined: Fri May 09, 2008 3:31 am

PHP + fatal error

Post 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 : :(
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: PHP + fatal error

Post by EverLearning »

Post some code. We're not clairvoyant(atleast most of us aren't ;))
anamika12345
Forum Newbie
Posts: 5
Joined: Fri May 09, 2008 3:31 am

Re: PHP + fatal error

Post 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
{

}
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: PHP + fatal error

Post 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');
anamika12345
Forum Newbie
Posts: 5
Joined: Fri May 09, 2008 3:31 am

Re: PHP + fatal error

Post 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????
DeFacto
Forum Commoner
Posts: 37
Joined: Wed Apr 23, 2008 2:30 pm

Re: PHP + fatal error

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP + fatal error

Post by RobertGonzalez »

Which file does the missing function live in? Once you know that, include that file.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: PHP + fatal error

Post 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.
Post Reply