Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:00:07+00:00 2026-05-26T17:00:07+00:00

This has been baffling me for a few hours now and I’m reaching the

  • 0

This has been baffling me for a few hours now and I’m reaching the point of giving up.

My project has 3 relevant files:

dbconfig.php
register.php
testmysql.php

dbconfig.php has this function:

        public function connString()
        {
            $connString['host'] = $this->host;
            $connString['username'] = $this->username;
            $connString['password'] = $this->password;
            $connString['database'] = $this->database;                      
            return $connString;
        }

I do this in testmysql.php and it works perfectly:

    require('dbconfig.php');
    $dbObject = new dbconfig();

    $conn = $dbObject->connString();
    mysql_connect($conn['host'],$conn['username'],$conn['password']) or die(mysql_error());
    mysql_select_db($conn['database']) or die(mysql_error());

But when I do the same thing in register.php, it fails:

<div class="div_texbox">
    <select id="field1" name="field1" class="textbox">                                              
        <option value="0">Select</option>
        <?php                                           
            require('dbconfig.php');
            $dbObject = new dbconfig();

            $conn = $dbObject->connString();
            mysql_connect($conn['host'],$conn['username'],$conn['password']) or die(mysql_error());
            mysql_select_db($conn['database']) or die(mysql_error());

            $result = mysql_query("SELECT * FROM table") or die ('error selecting');                                            

            while ($row = mysql_fetch_array( $result ))
            {
                echo "<option value=\"" . $row['ID'] . "\">" . $row['value'] . "</option>";
            }                                                       
        ?>                                          
    </select>
</div>

Details on when I say ‘it fails’:
Field1 is a select box that is supposed to populate, but it doesn’t and no further fields in the form show up (presumably because of the die).
I tried installing a PHP debugger to see the message being thrown but could not get one working.
If I hardcode in the connect parameters, it all works.
A var_dump of $conn shows it to be holding all the right values at all the right indices (also evident in the fact that testmysql.php works).

Also, it some troubleshooting made it seem that it is failing at mysql_connect

I analyzed my HTML code of the rendered page to see the output of the PHP script and this is what it shows:

( ! ) Fatal error: Cannot redeclare class dbconfig in C:\wamp\www\site\dbconfig.php on line 10
Call Stack
#TimeMemoryFunctionLocation
10.0005698544{main}(  )..\register.php:0
21.2728763824require( 'C:\wamp\www\site\dbconfig.php' )..\register.php:106

dbconfig constructor

public function __construct($config = NULL)
        {
            if ($config != NULL)
            {
                $this->host = $config['hostname'];
                $this->database = $config['database'];
                $this->username = $config['username'];
                $this->password = $config['password'];
            }
            else
            {
                $this->host = $this->defaultConfig['hostname'];
                $this->database =$this->defaultConfig['database'];
                $this->username = $this->defaultConfig['username'];
                $this->password = $this->defaultConfig['password'];

            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:00:08+00:00Added an answer on May 26, 2026 at 5:00 pm

    Looks like you’re including dbconfig.php more than once which is causing the cannot redeclare class fatal error.

    Change any reference of

    require('dbconfig.php')
    

    to

    require_once 'dbconfig.php';
    

    While you’re at it, stop using or die() and switch to PDO and parameterised statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me nuts for hours now. Consider the following test script
This has been stumping me for a few days now. I have a stored
So i feel like a noob but this has been baffling me or hours
This has been baffling me recently, and I can't seem to find a suitable
This has been driving me crazy for the past few minutes I have a
This has been bugging me for more than two days now, so i thought
This has been driving me crazy for the past couple of hours. I have
This has been grinding my gears for at least a week now. I have
This has been driving me mad for a few days... Create a new Window-based
This has been driving me crazy for the last couple of hours. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.