How to check if something was passed to the php page?

1

It's even hard to ask because I do not know if it's okay, but I'll try to explain it as best I can. I have a page where I will use the php switch case to decide the action according to what is passed. However, if the page is only triggered without passing any parameters, it should check the following:

$query = "SELECT * FROM duelos WHERE data > UNIX_TIMESTAMP() - 1440 AND (iddesafiante=$desafiante AND iddesafiado=$desafiado) OR (iddesafiante=$desafiado AND iddesafiado=$desafiante)";
$statement = $mysqli->prepare($query);

 //bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
 $statement->bind_param(ii, $iddesafiante, $iddesafiado);

 if($statement->execute()){
print 'Success! Ja duelou com esse oponente nas ultimas 24horas <br />';
 }else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();

After the first check, make the decisions accordingly, if something happens

 $acao = $_GET (acao);
 switch($acao) {
 case desafiar: {
    QUERY 1
    break;
 }
  case recusar: {
    query 2
    break;
 }

}
}
    
asked by anonymous 14.02.2016 / 01:42

1 answer

2

You have two options, check if there is something and execute the desired code, or throw that code block in the default ( default ) of the switch.

The difference between the two is, the first executes or calls a certain code block only when $_GET['acao'] is not defined. The second will excuse that code when none of the previous options of the switch are satisfied ie it will enter default when $acao has no value or any other value than specified in case in this example 123 drops no default .

1 - Option

if(!isset($_GET['acao']){
//executa algo
}

switch($acao){

2 - Option

switch($acao) {
    case desafiar: {
        QUERY 1
        break;
     }
    case recusar: {
        query 2
        break;
     }
      default:{
           //esse bloco é executado quando nenhuma das condições for satisfeita
     }

    }
}
    
14.02.2016 / 01:51