[PLUG] Another PHP & MySQL problem

Robbert van Andel robbert at vafam.com
Sat Mar 23 16:21:28 UTC 2002


Are you sure that the pages you are including don't include other pages
that declare the function as well, causing the redeclaring of the
function?

Robbert

-----Original Message-----
From: plug-admin at lists.pdxlinux.org
[mailto:plug-admin at lists.pdxlinux.org] On Behalf Of Richard Steffens
Sent: Saturday, March 23, 2002 8:15 AM
To: plug
Subject: [PLUG] Another PHP & MySQL problem

I'm working on another exercise in the book, "PHP and MySQL Web
Development" and have hit another problem. For this exercise, the
authors are using the technique of collecting related code in files and
using include, include_once, or require_once to use the code.

The exercise in chapter 25 if building a shopping cart. All the code is
supplied on a CD, which I have copied onto my hard disk in the directory
/var/www/html/PHPandMySQLbook/source/chapter25. I have an index.php file
in /var/www/html from which I link to the index.php file in the
directory containing the files for chapter 25.

When I click on that link, I get the following error message:

Fatal error: Cannot redeclare db_connect() in db_fns.php on line 3

Chapter 25's index.php starts with this line:

  include ('book_sc_fns.php');

book_sc_fns.php starts with this line:

  include_once("db_fns.php");

And db_fns.php starts like this:

function db_connect()
{
   $result = @mysql_pconnect("localhost", "book_sc", "password");
   if (!$result)
      return false;
   if (!@mysql_select_db("book_sc"))
      return false;

   return $result;
}

The database book_sc was created using the mysql monitor, and yes, the
password is "password." (It's an exercise. The real world will never see
it.)

Since the line, "function db_connect()" only shows up once, I don't see
how it could have been previously declared. Any ideas?

-- 
Regards,

Dick Steffens
"Quando Omni Flunkus Moritati"
http://rsteff.home.attbi.com/

_______________________________________________
PLUG mailing list
PLUG at lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug






More information about the PLUG mailing list