How to check if something has been passed to the php page?

Asked

Viewed 110 times

1

It is even difficult to ask because I do not know if this is right, but I will try to explain it in the best way possible. I have a page where I will use the php case switch to decide the action according to what is passed. However, I need the page if it is only triggered without passing any parameters it makes the following check:

$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();

Dai after the first check take the settlement decisions if something is passed

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

}
}
  • 1

    Play this code on default switch, http://php.net/manual/en/control-structures.switch.php

  • that was put in the answer so I mark as a solution

1 answer

2


Have two options, check if there is something and execute the desired code or throw this code block in the default case(default) switch.

The difference between the two is, the first executes or calls a particular block of code only when $_GET['acao'] is not defined. The second will execute that code when none of the previous switch options are satisfied or will enter the default when $acao has no value or other value than those specified in case in this example the 123 fell in the 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
     }

    }
}
  • clarified further

  • Now, do I need to ask you another question or do I need to clear it up here? Because I realized that the check will have to be done in all (case), da para usar isso ainda no swith ou teria que fazer a verificacao em todos case?

  • @Arsomnolasco the isset check?

  • It is because in type this file will be updating every 5 minutes, then in case it can not be default because users will not be asking all the time, the defaut in case will be an echo " advertisement"; in the same case it will be executed only within the same case=challenge 1 performs the check, if it meets the check it goes to 2º = Challenge Index . The same goes for the other cases there will always be this first check. I understood

  • @Arsomnolasco better ask another question :)

Browser other questions tagged

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