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 } ?>  
3
  • 1
    Instead of explaining your code, why not just paste it here? It would be much easier to help you. Commented Feb 4, 2016 at 10:13
  • 2
    The error is pretty clear: you're probably including the function twice Commented Feb 4, 2016 at 10:14
  • hey guys, if i dont add the db file twice i dont get any output,thats also to note please Commented Feb 4, 2016 at 10:24

1 Answer 1

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".

Sign up to request clarification or add additional context in comments.

3 Comments

You will have to use include_once on all instances of including db_pconnect()
if i use include for one page and is it neccessary that i should use the same for the same page in another page ?
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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.