Return "Alert" if an IF is not executed

Asked

Viewed 40 times

1

How can I check whether an if was executed or not, and whether it was not it to display an Alert?

Take the example:

if ($newtime!=0) {
   $qryupd = "update registration set dados=" . $dadosnew . " where id=$id";
   $result2 = mysqli_query($db, $qryupd);
   if (!$result2) {
      rollback();
      echo '[{"resultado":"falhou","total_lances":"' . $bal . '","motivo":"Falha ao executar lance, por favor tente novamente! Código: LW102"}]';
      exit;
   }
}

In this example it already does this for the query that updates in DB, if it does not update it shows Alert. I need to do the same thing, but I need him to check the first IF condition, in case: if ($newtime!=0) {

It is possible to do this?

1 answer

1


            if ($newtime!=0) {
        $qryupd = "update registration set dados=" . $dadosnew . " where id=$id";
        $result2 = mysqli_query($db, $qryupd);
        if (!$result2) {
            rollback();
            echo '[{"resultado":"falhou","total_lances":"' . $bal . '","motivo":"Falha ao executar lance, por favor tente novamente! Código: LW102"}]';
            exit;
        }
        }else{
    echo "newtime é igual a 0";
    echo "<script>alert('VARIAVEL $NEWTIME É IGUAL A 0')</script>;

}

I think this will solve your problem. You can use IF/ELSE .

if(condicao)
{
entrou na condição
}else{
não entrou na condição
}

Browser other questions tagged

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