$_GET does not receive more than one variable

Asked

Viewed 50 times

0

There is the following link.

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

If yes was clicked the variable Resp = ’s', if no is clicked, Resp = 'n'

Page authorize

<?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 it was not possible to find the Resp variable.

Notice: Undefined variable: Resp in C: Program Files (x86) Easyphp-Devserver-16.1 eds-www Accipiter Commercial authorize.php on line 8

I believe it’s a mistake mine easy to resolve, but I’m not getting it right.

1 answer

2


The problem is not that $_GET does not receive the value, but in 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 nowhere, so will generate the message

Undefined variable: SP

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

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

And in your call pass the new parameter:

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

Or, as 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;
    ....
}
  • That’s right! I forgot to pass by parameter! Mistake that should not be made long ago! haha vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.