0

Hello for eveybody i have a trouble whit this

$aux=0;
if($resultado=='true'){
   echo "<script type='text/javascript'>\n";
   echo "alert('$resultado');\n";
   echo "</script>";
}
else{
    if ($aux==0) {
        echo "<script type='text/javascript'>\n";
        echo "alert('$resultado');\n";
        echo "</script>";
        $aux=1;
    }      
}

if ($resultado = true) its work fine but if ($resultado = false) dont show javascript code

Thanks in advance.

3 Answers 3

2

Get rid of the quotes around 'true' (and 'false'). This makes them strings and strings that are not empty always equate to true. This is because of type juggling in PHP.

if($resultado==true){

and

if($resultado==false){
Sign up to request clarification or add additional context in comments.

Comments

0

there is no need to check wheather true and false as you just need to pass variable in if conditions and if condition just check the return true or false.Below is code

$aux=0;
if($resultado  ){
   echo "<script type='text/javascript'>\n";
   echo "alert('$resultado');\n";
   echo "</script>";
}
else{
    if (!$aux  ) {
        echo "<script type='text/javascript'>\n";
        echo "alert('$resultado');\n";
        echo "</script>";
        $aux=1;
    }      
}

Comments

0
 $aux=0;
if($resultado=='true'){
   echo "<script type='text/javascript'>\n";
   echo "alert('$resultado');\n";
   echo "</script>";
}
else if ($aux==0) //-------->Brush up on your syntax for control structures
 {    
        echo "<script type='text/javascript'>\n";
        echo "alert('$resultado');\n";
        echo "</script>";
        $aux=1;
  }      

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.