FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Redeclared function problem





DoctorBeaver
I've got a page with a javascript form. The form's ACTION is to reload the same page and I'm checking whether the submit button is set to control program flow.

At the top of the page I've got 3 include statements...
Code:

include "../includes/mysql_connect.php";
include "../classes/safesql_class.php";
include "includes/quiz_funcs.php";


In quiz_funcs.php I've got the following function...
Code:

function redirect($next_page, $delay)
{
   echo '<meta http-equiv="Refresh" content="'.$delay.';url='.$next_page.'">';
}


When the page reloads after clicking the submit button in the form, I get the following...

Fatal error: Cannot redeclare redirect() (previously declared in W:\www\beaverland_2007_v01\quiz\includes\quiz_funcs.php:3) in W:\www\beaverland_2007_v01\quiz\includes\quiz_funcs.php on line 3

I've used this technique in lots of places and I can't understand what's going wrong in this instance. Anyone got any ideas?
Star Wars Fanatic
I think somehow you are calling the function twice.

Go through your code and make sure you only call it once.
Make sure it isn't in a loop, or anything like that.
DoctorBeaver
It's not in a loop. Here's the code from the top of the page to the end of the head tag...
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Beaverland Quiz</title>
    <meta http-equiv="Content-Language" content="FI" />
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
   
    <link rel="stylesheet" type="text/css" media="screen" href="../default/styles/style.css" />
<?php

include "../includes/mysql_connect.php";
include "../classes/safesql_class.php";
include "includes/quiz_funcs.php";

$browser ="*".$_SERVER['HTTP_USER_AGENT'].'</br>';
if (strstr($browser, 'Opera')){
   echo '<link rel="stylesheet" type="text/css" media="screen" href="../default/styles/opera.css" /></br>';

}
?>

</head>
DoctorBeaver
I'm more puzzled now.

I removed that function from quiz_funcs.php, put it in the main functions file and included that at the top of the page thus...

Code:

include "../includes/mysql_connect.php";
include "../functions/functions.php";
include "../classes/safesql_class.php";
include "includes/quiz_funcs.php";


Now I get the same error but for what was the 2nd function declaration in quiz_funcs.php (it's now the 1st declaration, of course)
AftershockVibe
This usually happens when you have cyclic inclusions. Eg page1.php includes functions.php and page2.php which also includes functions.php. Your code might be doing this... although that doesn't make a lot of sense because it only seems to do it when you refresh.

From your code I can't see why it's doing this but basically you are defining the function twice. Changing the include()s to include_once()s should fix it.
DoctorBeaver
I've looked & looked & I can't see any loops or includes that are including the include. I've done it a different way now & it works so I'm not going to worry about it any more.

Thanks for your help anyway.
Related topics
Header("Location: PROBLEM");
ASP Problem
SMTP problem
[HELP] PC PROBLEM (don't bind)
terrorism in israel
PHP Problem: Unable to execute ext. commands
A minor printing problem
javascript function not being seen
Password problem
(server 2) php function exif_read_data() not supported ?
problem with registration notify mod
ScanDir function problem
Like and % Function Problem..
Including file with same definition on Win & Linux
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.