0

I have a panel.php in which I load my different pages by the include method. As there is a single panel, the message display system must be included here, and there will not always an error id to be displayed.

I have added the following code to my panel, calling function "envioMensaje" in case there is getting any variable 'msg':

<?php
if ($_GET) {
    if ($_GET['msg']) {
        $id_mensaje=$_GET['msg'];
        $mensaje=envioMensaje($id_mensaje);
        echo $mensaje;
    }
}
?>

This works fine when a message id is sent, but when not I get a "Undefined index: msg in..." error. I have tried also:

if ($_GET) {
    if ($_GET['msg']) {
        $id_mensaje=$_GET['msg'];
        $mensaje=envioMensaje($id_mensaje);
        echo $mensaje;
    } else {
        echo"";
    }
}

And some other variations with no result. Why is it always looking for 'msg'? Could it be because on that same document I have this other conditional asking for $_GET? (i need it for the content to be loaded):

if (!$_GET) {
    include('config/shortcuts.php');
} else {    
    $directorio = $_GET['directory'];
    include('config/'.$directorio);
}

2 Answers 2

4

Use isset() to check if a variable exists without throwing a PHP notice.

if (isset($_GET['msg'])) {
    //then use $_GET['msg']
}
Sign up to request clarification or add additional context in comments.

1 Comment

That's the answer I was going to give. You beat me to it. +1
1

Check for

if(isset($_GET['msg'])){...}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.