Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP error - cannot redeclare function [duplicate]

Tags:

php

I have a JavaScript function making a call to a PHP script. So far so good. A problem happens when I try to do this:

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

When I import my connection file, it gives me an error that the functions in that file have already been 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 it is referring to is a function that is in the connect script.

But if I remove the

include '../connect.php';

Then it will just tell me that I can not use the mysql_real_escape_string function. So I am kind of stuck between not being able to use either option.

like image 467
Genadinik Avatar asked Jun 10 '11 16:06

Genadinik


3 Answers

try include_once '../connect.php'; it'll make sure you're only including once this file

like image 154
afarazit Avatar answered Nov 20 '22 18:11

afarazit


Take a look at your files and your includes... You are declaring that function twice, that is the error. It has nothing to do with MySQL, database connections, or mysql_real_escape_string().

I.e. You may be including file A and file B, but file A already includes file B... You can either figure out where your includes are going wrong, or use include_once or require_once to prevent it from double-loading.

like image 37
Fosco Avatar answered Nov 20 '22 18:11

Fosco


Likely you are including the file multiple times. Use require_once instead of include.

like image 2
datasage Avatar answered Nov 20 '22 18:11

datasage