tags:

views:

76

answers:

5

im getting this error message

Fatal error: Cannot redeclare get_db_conn() (previously declared in `/home/maxer/domains/x/public_html/xmasapp/dbfuncs.php:21) in /home/maxer/domains/x/public_html/xmasapp/dbfuncs.php on line 24`

this is the code

function get_db_conn() {
  $conn = mysql_connect($GLOBALS['db_ip'], $GLOBALS['db_user'], $GLOBALS['db_pass']);
  mysql_select_db($GLOBALS['db_name'], $conn);
  return $conn;
}

line 21 refers to

$conn = mysql_connect($GLOBALS['db_ip'], $GLOBALS['db_user'], $GLOBALS['db_pass']);

line 24 is the closing curly bracket of the function

the code worked fine until I tried to clean my code up, I ripped most of the "view" code out and put it into separate files but didn't change any logic

+3  A: 

You are most likely including a file twice or including two files that include the same file each.

You can prevent this by using include_once() or setting up a better structure of what you include when.

EDIT

Try this and see if you see an error in your include setup.

echo "<pre>";
print_r(get_included_files());
echo "</pre>";

Somewhere you're including a file twice or some two files has a definition of your function.

Ólafur Waage
But I Don't see why then its dumping the error for the follow line of the function declaration? tried include_once made no difference
chris
narrowed it down.. had two index files that I uploaded to the wrong folders. thanks for the helps
chris
+1  A: 

Is this in an includes file? Is the includes file getting included more than once?

It's complaining because the get_db_conn is defined more than once, and most likely it's getting included multiple times unless you have that function in two different places.

Ryan Smith
from what I see the file is only included once- all my db functiosn are in the one file and I have included it in the main index.php- thats where am stuck- on @Ólafur advices below I switched to include_once but made no difference
chris
+1  A: 

Your error message says:

Cannot redeclare get_db_conn() (previously declared in [...]/dbfuncs.php:21) in [...]/dbfuncs.php on line 24

You have a function named get_db_conn() that you are declaring multiple times. Is your dbfuncs.php file including itself?

Daniel Pryden
A: 

It's possible you're include()ing the same file more than once. For this reason I like to use include_once() whenever possible.

echo
A: 

You declare two functions with identical names (both are called get_db_conn())

Michael Mao