Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fatal error: Cannot redeclare connecttodatabase()

    hello, I keep getting the error:

    Fatal error: Cannot redeclare connecttodatabase() (previously declared in /srv/disk2/1645054/www/strings.atwebpages.com/config.php:31) in /srv/disk2/1645054/www/strings.atwebpages.com/config.php on line 35

    I looked through my code and did not see any repeats. Here is the config.php :

    PHP Code:
    <?php
    session_start
    ();

    /*///////////////////////////////////////////////////
    This file will simplify all code by holding valueus and functions
    ///////////////////////////////////////////////////*/
    //create MySQL server information constants
    define('DB_HOST''*');
    define('DB_USER''*');
    define('DB_PASSWORD''*');
    define('DB_DATABASE''*');
        
    //session_start();

    ////////////////////////////////////////////////////////////////////////////////
    // Connect to database

    function connectToDatabase(){
        
        
    //session_start();
        
    mysql_connect(DB_HOSTDB_USERDB_PASSWORD) or die("MySQL Error: " mysql_error()); // Connect to database server
        
    mysql_select_db(DB_DATABASE) or die("MySQL Error: " mysql_error()); // Select registrations database.
        
    }
    And here is the page generating the error:

    PHP Code:

    <?php //include("config.php"); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title> strings DEV </title>
            <link href="home.css" type="text/css" rel="stylesheet" />
            
            <link rel="icon" 
                  type="image/png" 
                  href="favicon.png"/>
            
        </head>
        
        <body>
            
            <?php
         
            
    // At the top of the page we check to see whether the user is logged in or not 
            
    if(empty($_SESSION['username'])) {
                
                
    // If they are not, we redirect them to the login page. 
                
    echo '<meta http-equiv="refresh" content="0;index.php">';
                
             
                
    // Remember that this die statement is absolutely critical.  Without it, 
                // people can view your members-only content without logging in. 
                
    die("Redirecting to main page"); 
            } else {
             
                
                
            }
            
            
    ?>
    And the function is called in my index.php code. I do not se any recalls, so I do not know what is generating the error.

    Thank You!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Your config.php script you've posted isn't long enough to trigger the error lines listed. The one you need has at least 36 lines of code in it, this one only has 24.
    The second page doesn't include the file, so that cannot be the initiating script.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the whole config.php code:

    [PHP]
    <?php
    session_start();

    /*///////////////////////////////////////////////////
    This file will simplify all code by holding valueus and functions
    ///////////////////////////////////////////////////*/
    //create MySQL server information constants
    define('DB_HOST', '*');
    define('DB_USER', '*');
    define('DB_PASSWORD', '*');
    define('DB_DATABASE', '*');

    //session_start();

    /*//The link variable is the connection to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    //If link fails to connect then display error message, failed to connect to server
    if(!$link) { die('Failed to connect to server: ' . mysql_error()); }

    //The db variable selects the database to connect to
    $db = mysql_select_db(DB_DATABASE);

    //If db does not connect show error message, unable to select database
    if(!$db) { die("Unable to select database"); } */

    ////////////////////////////////////////////////////////////////////////////////
    // Connect to database

    function connectToDatabase(){

    //session_start();
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("MySQL Error: " . mysql_error()); // Connect to database server
    mysql_select_db(DB_DATABASE) or die("MySQL Error: " . mysql_error()); // Select registrations database.

    }

    ////////////////////////////////////////////////////////////////////////////////
    // See if a user exists

    function checkIfUsernameExists($name, $tableName){

    $bool = true;

    $sql_name_check = mysql_query("SELECT username FROM '".$tableName."' WHERE username='".$name."'") or die(mysql_error());
    $name_check = mysql_num_rows($sql_name_check);

    if($name_check > 0){

    $bool = true;

    } else {

    $bool = false;

    }

    return $bool;

    }

    ////////////////////////////////////////////////////////////////////////////////
    // See if an email exists

    function checkIfEmailExists($email, $tableName){

    $bool = true;

    $sql_name_check = mysql_query("SELECT username FROM '".$tableName."' WHERE username='".$email."'") or die(mysql_error());
    $name_check = mysql_num_rows($sql_name_check);

    if($name_check > 0){

    $bool = true;

    } else {

    $bool = false;

    }

    return $bool;

    }

    ////////////////////////////////////////////////////////////////////////////////
    // Insert a user into the database

    function insertUserIntoDatabase($username, $email, $password, $tableName){

    $name = mysql_real_escape_string($_POST['name']); // Turn our post into a local variable
    $email = mysql_real_escape_string($_POST['email']); // Turn our post into a local variable
    $password = mysql_real_escape_string($_POST['password']);//turn our post into a local variable

    mysql_query("INSERT INTO '".$tablename."' (username, password, email, hash) VALUES(
    '". mysql_real_escape_string($name) ."',
    '". mysql_real_escape_string(md5($password)) ."',
    '". mysql_real_escape_string($email) ."',
    '". mysql_real_escape_string($hash) ."') ") or die(mysql_error());

    }

    ////////////////////////////////////////////////////////////////////////////////
    // Activate the user

    function ActivateUser(){

    $msg = '';

    // Verify data
    $email = mysql_escape_string($_GET['email']); // Set email variable
    $hash = mysql_escape_string($_GET['hash']); // Set hash variable

    $search = mysql_query("SELECT email, hash, active FROM users WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error());

    $match = mysql_num_rows($search);

    if($match > 0){

    // We have a match, activate the account
    mysql_query("UPDATE users SET active='1' WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error());

    $msg = "Your account has been activated";

    }else{

    // No match -> invalid url or account has already been activated.
    $msg = "Invalid link";

    }

    }

    ////////////////////////////////////////////////////////////////////////////////
    // Login the user

    function login($username, $password, $tableName){

    $search = mysql_query("SELECT username, password, active FROM users WHERE username='".$username."' AND password='".$password."' AND active='1'") or die(mysql_error());
    $match = mysql_num_rows($search);

    if($match > 0){

    session_register("username");
    session_register("password");
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password;
    echo '<meta http-equiv="refresh" content="0;home.php">';

    }else{

    $msg = 'Login Failed! Please make sure that you enter the correct details and that you have activated your account.';

    }

    }





    ?>
    [PHP]

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    A copy and paste of this code passes a lint test. This code you've provided does not trigger a redeclared function code.
    What can do this though is the inclusion of a function more than once into another document, but, if you are to do that the error message would tell you what file it is:
    Fatal error: Cannot redeclare connecttodatabase() (previously declared in /file/first/declared:line#) in /file/throwing/error on line #
    The error you have posted implies that either the config.php script in use is redeclaring the function name, or including itself or another file which declares the same function name into it.

    Out of curiosity, why is your config script dealing with so much functionality? Also, this won't work; register globals are long gone and shouldn't have been used for years prior to their official removal anyway:
    PHP Code:
    session_register("username");
    session_register("password"); 
    I should point out as well that the function isn't required at all since you automatically establish a connection anyway.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •