0

I have a page header.php which have all the fuctions and db connection pages included in them, i made another page sidebar.php and i included it into another page category.php

So now 1.header.php - inside header config.php,functions.php 2.category.php - inside this includes header.php and sidebar.php

The problem is the db connection made in the sidebar.php is having error or not connecting when i take the url sidebar.php while includeing the config.php file i get the correct output if not i have nothing

when i include the config in sidebar.php and then include sidebar.php in category.php page i get error

"Fatal error: Cannot redeclare db_pconnect() in /var/www/clients/client9/web35/web/beta3/classes/dblib.inc on line 16"

Code: header.php

<?php
        require_once '../classes/config.php';
        $cur_file = basename($_SERVER['PHP_SELF']);

        if ($login_required == "YES" && empty($_SESSION['SESS_MEMBER_ID'])) {
            header("location:../login.php");
        }

        require_once '../functions.php';
        ?>

category.php

<?php require_once("templates/header.php"); ?> 
            <?php include("category_bar.php"); ?> 
               <div class="container">
              <div class="content-second">
              <div class="row">

sidebar.php

 <?php require_once("templates/header.php"); ?> 
        <div class="container-fluid">
            <div class="row">

The page which i needs data code is

<?php                                                   
$sql_cat_1 = db_query("Select * from jp_newcat where ncat_parentid='0'");
while($sql_cat_res = db_fetch_object($sql_cat_1)){
?>
<li><a href="category.php?cid=<?php echo $sql_cat_res->ncat_id; ?>"><?php echo $sql_cat_res->ncat_name; ?></a></li>
<?php } ?>  
Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44
Adhip
  • 29
  • 10

1 Answers1

2

As per the error, you are including files more than once. You cannot declare the same function twice. You can use "include_once" instead of using "include".

  • You will have to use include_once on all instances of including db_pconnect() – Nuwan Chinthana Feb 04 '16 at 10:33
  • if i use include for one page and is it neccessary that i should use the same for the same page in another page ? – Adhip Feb 04 '16 at 10:38
  • Yes. the only difference being that if the code from a file has already been included, it will not be included again. This need to be repeated in all instances including this function db_pconnect() – Nuwan Chinthana Feb 04 '16 at 10:50