pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PHP function error
5+ messages / 3 participants
[nested] [flat]

* PHP function error
@ 2005-03-02 09:43  Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
  1 sibling, 2 replies; 5+ messages in thread

From: Sarah, Godfrey, Matthew & Vera @ 2005-03-02 09:43 UTC (permalink / raw)
  To: pgsql-php

I am trying to run the following code but get the following error:

Fatal error: Call to undefined function show_title() in 
d:\webhost\build\index.php on line 13


This file is called "index.php"

<? include "dynamic.php"; ?>
<? if (empty($id)) $id = "Home"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
         <title> <? show_title($id); ?> </title>
</head>
<body>
<? show_navigation($id); ?>
<? show_content($id); ?>
</body>
</html>

The other file "dynamic.php" has the following functions

/* dynamic.inc.php */


function show_title($id)
{
   $fp = fopen(get_filename($id), "r");
   if (!$fp) return;
   $line = trim(fgets($fp, 255));
   fclose($fp);
   echo $line;
}



function get_filename($id)
{
   $name = "file_$id.txt";
   if (file_exists($name))
   {
     return $name;
   } else {
     return "error.txt";
   }
}


function show_navigation($id)
{
   global $PHP_SELF, $SCRIPT_NAME;
   if (trim($PHP_SELF) == "") $PHP_SELF = $SCRIPT_NAME;
   $dir = opendir('.');
   if (!$dir) return;
   while ($file = readdir($dir))
   {
     if ( (ereg("^file_.*\.txt$", $file)) and (is_file($file)) )
     {
       $item = ereg_replace("^file_(.*)\.txt$", "\\1", $file);
       echo '<a href="'.$PHP_SELF.'?id='.urlencode($item).'">'.$item."</a>\n";
       if ($id == $item)
       {
         echo "<==";
       }
       echo "<br>\n";
     }
   }
}



function show_content($id)
{
   $fp = fopen(get_filename($id), "r");
   if (!$fp) return;
   $first = true;
   while (!feof($fp))
   {
     if ($fp)
     {
       $line = fgets($fp, 1024);
       if ($first)
       {
         $first = false;
       } else {
         echo $line;
       }
     }
   }
   fclose($fp);
} 





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PHP function error
@ 2005-03-02 11:26  graeme <graeme_foster@sherubtse.edu.bt>
  parent: Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
  1 sibling, 0 replies; 5+ messages in thread

From: graeme @ 2005-03-02 11:26 UTC (permalink / raw)
  To: Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>; +Cc: pgsql-php

Is dynamic.php in the same directory as index.php, switch your stetement 
from include to require if it fails to find it them you'll learn where 
it is looking for the file.

Just for future reference some servers require you php tags to be 
written as <?php ... ?>

graeme.

Sarah, Godfrey, Matthew & Vera wrote:

> I am trying to run the following code but get the following error:
>
> Fatal error: Call to undefined function show_title() in 
> d:\webhost\build\index.php on line 13
>
>
> This file is called "index.php"
>
> <? include "dynamic.php"; ?>
> <? if (empty($id)) $id = "Home"; ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
>         <title> <? show_title($id); ?> </title>
> </head>
> <body>
> <? show_navigation($id); ?>
> <? show_content($id); ?>
> </body>
> </html>
>
> The other file "dynamic.php" has the following functions
>
> /* dynamic.inc.php */
>
>
> function show_title($id)
> {
>   $fp = fopen(get_filename($id), "r");
>   if (!$fp) return;
>   $line = trim(fgets($fp, 255));
>   fclose($fp);
>   echo $line;
> }
>
>
>
> function get_filename($id)
> {
>   $name = "file_$id.txt";
>   if (file_exists($name))
>   {
>     return $name;
>   } else {
>     return "error.txt";
>   }
> }
>
>
> function show_navigation($id)
> {
>   global $PHP_SELF, $SCRIPT_NAME;
>   if (trim($PHP_SELF) == "") $PHP_SELF = $SCRIPT_NAME;
>   $dir = opendir('.');
>   if (!$dir) return;
>   while ($file = readdir($dir))
>   {
>     if ( (ereg("^file_.*\.txt$", $file)) and (is_file($file)) )
>     {
>       $item = ereg_replace("^file_(.*)\.txt$", "\\1", $file);
>       echo '<a 
> href="'.$PHP_SELF.'?id='.urlencode($item).'">'.$item."</a>\n";
>       if ($id == $item)
>       {
>         echo "<==";
>       }
>       echo "<br>\n";
>     }
>   }
> }
>
>
>
> function show_content($id)
> {
>   $fp = fopen(get_filename($id), "r");
>   if (!$fp) return;
>   $first = true;
>   while (!feof($fp))
>   {
>     if ($fp)
>     {
>       $line = fgets($fp, 1024);
>       if ($first)
>       {
>         $first = false;
>       } else {
>         echo $line;
>       }
>     }
>   }
>   fclose($fp);
> }
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>      subscribe-nomail command to majordomo@postgresql.org so that your
>      message can get through to the mailing list cleanly
>
>

-- 
Experience is a good teacher, but she sends in terrific bills.

Minna Antrim





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [**POSSIBLE SPAM**] PHP function error
@ 2005-03-02 13:31  Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
  parent: Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
  1 sibling, 0 replies; 5+ messages in thread

From: Sarah, Godfrey, Matthew & Vera @ 2005-03-02 13:31 UTC (permalink / raw)
  To: pgsql-php

At 02:47 PM 3/2/2005, you wrote:

>the file name in your include is wrong please use dynamic.inc.php instead of
>dynamic.php
>
>:)

Thanks but that is what I started with and still it could not work. Let me 
do that again.

Godfrey 





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PHP function error
@ 2005-03-02 13:53  Frank Bax <fbax@sympatico.ca>
  1 sibling, 0 replies; 5+ messages in thread

From: Frank Bax @ 2005-03-02 13:53 UTC (permalink / raw)
  To: pgsql-php

At 04:43 AM 3/2/05, Sarah, Godfrey, Matthew & Vera wrote:

>I am trying to run the following code but get the following error:
>
>Fatal error: Call to undefined function show_title() in 
>d:\webhost\build\index.php on line 13
>
>
>This file is called "index.php"
>
><? include "dynamic.php"; ?>
><? if (empty($id)) $id = "Home"; ?>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>< <? show_navigation($id); ?> <? show_content($id); ?>
>The other file "dynamic.php" has the following functions
>
>/* dynamic.inc.php */


Five (at least) problems:

1)  you error message says that error occured on line 13 of index.php, but 
the index.php file you show us does not have 13 lines in it.

2) You say the include file is called "dynamic.php", but the first line of 
that file has "dynamic.inc.php" - which is it.

3) You should normally use "require" instead of "include" in this situation.

4) I'm guessing you are running with "register_globals" on, which not a 
good idea; if it is off, the above code (line wid $id) will not work.

5) These problems have nothing to do with PostgresSQL, so this post is 
off-topic.  I suggest you find a php newbie list.




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PHP function error
@ 2005-03-02 14:04  Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Sarah, Godfrey, Matthew & Vera @ 2005-03-02 14:04 UTC (permalink / raw)
  To: pgsql-php

Hello Mr. Bax,

Many thanks for your kind comments.

-------
5) These problems have nothing to do with PostgresSQL, so this post is 
off-topic.  I suggest you find a php newbie list.
-------

I guess you are saying any inquiry here should be PosgresSQL/php related.

I will be careful in future.    :-)

Godfrey





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2005-03-02 14:04 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-02 09:43 ` Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
2005-03-02 11:26   ` graeme <graeme_foster@sherubtse.edu.bt>
2005-03-02 13:31   ` Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>
2005-03-02 13:53 ` Frank Bax <fbax@sympatico.ca>
2005-03-02 14:04 Re: PHP function error Sarah, Godfrey, Matthew & Vera <kyedza@sdf.lonestar.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox