$ _GET does not receive more than one variable

0

The following link exists.

<a style='color: bfbfbf; text-decoration: none;' href='autorizar.php?id=<?php echo $curso[0]['idCurso'].'&resp=s' ?>'>Sim</a>

If the yes was clicked the variable resp = 's', if it is not clicked, resp = 'n'

Authorize page

<?php include '../AB/ab.php'; 

    $id = $_GET['id'];
    $resp = $_GET['resp'];

    function autorizar($conexao, $id)
    {
        if($resp == 's')
        {
            $sqlAtrib = "UPDATE cursos SET exibirCurso='s' WHERE idCurso = $id";
            mysqli_query($conexao, $sqlAtrib);
            header("Location: curso2.php?curso=$id");
        }
        else
        {
            echo 'entrou no else';
        }
    }

        autorizar($conexao, $id);   
?>

However, only $ _GET ['id'] is working. And the error returned is that the resp variable could not be found.

  

Notice: Undefined variable: resp in C: \ Program Files (x86) \ EasyPHP-Devserver-16.1 \ eds-www \ Accipiter \ Commercial \ autorizar.php on line 8

I think it's an easy error error, but I can not resolve it.

    
asked by anonymous 03.07.2017 / 18:25

1 answer

2

The problem is not that $ _GET does not receive the value, but rather its function:

function autorizar($conexao, $id)
    {
        if($resp == 's')
        {
            $sqlAtrib = "UPDATE cursos SET exibirCurso='s' WHERE idCurso = $id";
            mysqli_query($conexao, $sqlAtrib);
            header("Location: curso2.php?curso=$id");
        }
        else
        {
            echo 'entrou no else';
        }
    }

You are not declaring $resp anywhere, so it will generate the message

  

Undefined variable: resp

What you need to do is change the function declaration by adding the variable:

function autorizar($conexao, $id, $resp)

And in your call pass the new parameter:

autorizar($conexao, $id,$resp); 

Or, since you are creating the function in the same PHP that has the variable resp , you can use the directive global :

function autorizar($conexao, $id){
    global $resp;
    ....
}
    
03.07.2017 / 18:41