PHP error - cannot override function

I have a JavaScript function calling a PHP script call. So far, so good. The problem occurs when I try to do this:

$hike_id = mysql_real_escape_string($_GET['hike_id']); 

When I import a connection file, it gives me an error that the functions in this file are already defined, and the error is this:

 [Fri Jun 10 12:34:43 2011] [error] [client 75.24.105.18] PHP Fatal error: Cannot redeclare hassuspicioushackerstrings() (previously declared in /home/webadmin/comehike.com/html/connect.php:16) in /home/webadmin/comehike.com/html/connect.php on line 40 

The error referenced is a function that is in the script connection.

But if I remove

 include '../connect.php'; 

Then it will just tell me that I cannot use the mysql_real_escape_string function. Therefore, I was kind of stuck between the inability to use any option.

+7
source share
5 answers

try include_once '../connect.php'; he will include only this file

+11
source

Take a look at your files and your included ones ... You declare this function twice, that is, an error. It has nothing to do with MySQL, database connections, or mysql_real_escape_string ().

those. You can include file A and file B, but file A already includes file B ... You can either find out where your inclusions go wrong, or use include_once or require_once to prevent double loading.

+3
source

You probably include the file several times. Use require_once instead of include.

+2
source

you cannot use mysql_real_escape_string () because connect.php will most likely configure the database connection. I guess there is another one (possibly "functions.php") that has the same function.

You probably have something like this:

function hassuspicioushackerstrings ($ input) {}

in your connect.php, you can add if(!function_exists('hassuspicioushackerstrings')) { and } around the function.

+1
source

Never create or declare a function inside another function. But you can use other functions inside the function. For example, the following is incorrect

 function addition($a, $b) { function subtraction(){ } return $a+$b; } 
0
source

All Articles