Redeclare random() error - php

I'm basically trying to include a php file on my index.php file for my usersystem. But I've ran into an error. This is the code I used:
<?php include("usersystem/index.php"); ?>
Error:
Fatal error: Cannot redeclare random() (previously declared in
/home/public_html/upload.php:2) in /homepublic_html/global.php on line
35
Upload.php: http://pastebin.com/YcJYF2hb
global.php on line 35 I have: }, part of the file is at http://pastebin.com/gMsiPa7Z
I don't understand what's going on?

You cannot declare two functions with the same name. Both the snippets included above contains a function named random defined. I suggest that you rename them to be more specific.

Related

Fatal error: Uncaught Error: Call to undefined function that is not in a class

So i am working on some code and have come across this error and its starting to bug me a little as i cant find out what is wrong
i have 2 files main.php and that includes functions.php now in the main file i have the following code
<?php
include "functions.php";
$NAME = GET_USER_NAME();
?>
That is all thats in the main file now in the functions file i have the following code
<?php
function GET_USER_NAME() {
return 'bob';
}
function GET_USER_AGE() {
return '5';
}
?>
now when i try and open main in my browser i get the error
Fatal error: Uncaught Error: Call to undefined function GET_USER_NAME() in /var/www/html/main.php:3 Stack trace: #0 {main} thrown in /var/www/html/main.php on line 3
i know the file is being included properly as i can run the function
GET_USER_AGE();
from the main file and it returns 5
The only possible solutions to your problem are :
A typo in the function called in the main, which is not the exact same as in your included file (case sensitivity ?)
The include references a file which is not the one you want (but has one of the 2 desired functions)
And also yes, as #Markus-Zeller says, don't use method names like that, as stated here : https://www.php-fig.org/psr/psr-1/#1-overview

Fatal error: Cannot redeclare imagecreatefrombmp()

I'm working on a simple imageboard based by TinyBoard (xampp), when I try to post with image, website gives me error for some reason:
Fatal error: Cannot redeclare imagecreatefrombmp() in C:\xampp\htdocs\inc\image.php on line 584
image.php:
[1]https://pastebin.com/xqj2NAuX
(584 line = 77 line)
PHP 7.2, any help?
ANSWER:
Just change the function name to something else on line 1:
function imagecreatefrombmp2($filename)
(from user3647971)
Just change the function name to something else on line 1 :
function imagecreatefrombmp2($filename) {
the error warns you that a function named exactly like this has already been declared. It's a built-in php function: http://php.net/manual/en/function.imagecreatefrombmp.php

Why im getting function redeclared fatal error when i have declared it only once?

function createStudentMarks($key)
{ echo "key".$key;exit; }
This is my function.
$StudentMarks=createStudentMarks($key);
And i have called function in same file like this n im getting fatal error. Y is it so can anyone please help me
Cannot redeclare createStudentMarks() (previously declared in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php:85) in /var/www/html/2016/S/Mcd_BuildStudentsMarks.php on line 85 This is the error wat im getting exactly
Most of the times, this is caused by accidentally requireing or includeing a file more than once.
This generally shows bad coding behavior, so first try to find if this is the case or not. Try to eliminate the second and so on requires or includes.
In any case, you can work around it but using include_once or require_once, which will not include the file on second or next calls.

PHP Fatal error: Cannot redeclare frm_dl() wordpress

i'm having a 500 internal server problem. http://www.bunchmag.com/
500 internal server error Fatal error: Cannot redeclare frm_dl
20130329T141539: www.bunchmag.com/index.php PHP Fatal error: Cannot
redeclare frm_dl() (previously declared in
/hermes/web09/aksjhfks/moo.bunchmagazinecom/bunch/index.php(1) :
eval()'d code:1) in
/hermes/web09/skjfljf/moo.bunchmagazinecom/bunch/wp-config.php(1) :
eval()'d code on line 10
my hosting tech support is working on it but any help would be greatly appreciated!
Locate where the function is being declared and wrap it in an if statement to ensure the function is not already declared.
if( !function_exists( "frm_dl" ) ){
function frm_dl(..){
...
}
}
this should solve the issue if its the same file being included twice.
alternatively, search for multiple files declaring the function and wrap each one in the conditional statement, or change on of the function names (if possible)

php fatal error- no idea why

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
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.
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.
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?
It's possible you're include()ing the same file more than once. For this reason I like to use include_once() whenever possible.
You declare two functions with identical names (both are called get_db_conn())

Categories