Home » Php » php – Fatal error: Cannot redeclare mss() (previously declared in *

php – Fatal error: Cannot redeclare mss() (previously declared in *

Posted by: admin July 12, 2020 Leave a comment

Questions:

I don’t understand, the function doesn’t exist, and even if I change it to some absurd names, it still doesn’t work. Can anyone find the problem?

function mss($value){
    $data = mysql_real_escape_string(trim(strip_tags($value)));
    return $data;
}

EDIT: I forgot to mention, its XAMPP

How to&Answers:

That will mean that you’ve either defined the function in two separate spots, or your including the same file twice.

Use include_once/require_once instead of include/require.

Answer:

Ben Rowe’s answer is almost assuredly the reason why it’s happening.

I don’t recommend this but you can always wrap your function in function_exists()

if(!function_exists("mss")) {

    function mss($value){
        $data = mysql_real_escape_string(trim(strip_tags($value)));
        return $data;
    }

}

This solution is messy. It’s almost always more preferable to find out WHY your file is being included twice or where this function is defined twice. But, for special circumstances this solution could be appropriate.

Answer:

If you’re keeping it in a separate file, are you including it more than once accidentally?

Answer:

include_once (not include) works as long as you have the function declared one time only in a separate .php file. Please double check that the Function is not mentioned elsewhere .

Answer:

You should : include_once
instead of : include