TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   syntax error??? (http://www.talkphp.com/general/5944-syntax-error.html)

gillweb 08-03-2011 03:57 PM

syntax error???
 
I have this code looking to check to make sure at least 1 checkbox is checked but i'm getting this error and not understanding where the error is.. help?

PHP Code:

If (empty($up == && $app == && $dep == && $sold == 2)) {
    
$error=1;
    
$error_message="<p class=\"message invalid\"> Select At Least 1 Stage <span class=\"close\">X</span> </p>";
    echo 
$error_message;
    } 

And here's the error:
Code:

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ')'

maeltar 08-03-2011 04:00 PM

Try...

Code:

If ( empty(($up == 2) && ($app == 2) && ($dep == 2) && ($sold == 2)) ) {
    $error=1;
    $error_message="<p class=\"message invalid\"> Select At Least 1 Stage <span class=\"close\">X</span> </p>";
    echo $error_message;
    }

Just re-read what you posted and you want it to meet any of the requirements ?

you need to change the && to ||

One is and, the "||" means or ..

Also as I have done in my example, each part needs to be evaluated, so you need to have each test bracketed..

Code:

<?php

$up = 2;
$app = 2;
$dep = 2;
$sold = 2;

  If ( ( ($up == 2) || ($app == 2) || ($dep == 2) || ($sold == 2) ) )
  {
      echo "OR is TRUE<br />";
  } else{
      echo "OR is False<br />";
  }
 
  If ( ( ($up == 2) && ($app == 2) && ($dep == 2) && ($sold == 2) ) )
  {
      echo "AND is TRUE<br />";
  }else{
      echo "And is FALSE<br />";
  }
?>


gillweb 08-03-2011 04:04 PM

This is the error i get with that code.
Code:

Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '$'

maeltar 08-03-2011 04:16 PM

Now try the code with one of the vars

Code:

$up = 2;
$app = 2;
$dep = 2;

// Incorrect value..
$sold = 5;

  If ( ( ($up == 2) || ($app == 2) || ($dep == 2) || ($sold == 2) ) )
  {
      echo "OR is TRUE<br />";
  } else{
      echo "OR is FALSE<br />";
  }
 
  If ( ( ($up == 2) && ($app == 2) && ($dep == 2) && ($sold == 2) ) )
  {
      echo "AND is TRUE<br />";
  }else{
      echo "AND is FALSE<br />";
  }
?>


maeltar 08-03-2011 04:17 PM

Now if you "invert" the selection using the logical NOT symbol !

Code:

<?php

$up = 2;
$app = 2;
$dep = 2;
$sold = 2;

  If ( !( ($up == 2) || ($app == 2) || ($dep == 2) || ($sold == 2) ) )
  {
      echo "OR is TRUE<br />";
  } else{
      echo "OR is FALSE<br />";
  }
 
  If ( !( ($up == 2) && ($app == 2) && ($dep == 2) && ($sold == 2) ) )
  {
      echo "AND is TRUE<br />";
  }else{
      echo "AND is FALSE<br />";
  }
?>


gillweb 08-03-2011 04:35 PM

This did it! Thanks!
Quote:

Originally Posted by maeltar (Post 32188)
Now if you "invert" the selection using the logincal NOT symbol !

Code:

<?php
 
  If ( !( ($up == 2) && ($app == 2) && ($dep == 2) && ($sold == 2) ) )
  {
      echo "AND is TRUE<br />";
  }else{
      echo "AND is FALSE<br />";
  }
?>




All times are GMT. The time now is 01:46 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0