TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-03-2011, 03:57 PM   #1 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default 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 ')'
gillweb is offline  
Reply With Quote
Old 08-03-2011, 04:00 PM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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 />";
  }
?>
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 08-03-2011, 04:04 PM   #3 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default

This is the error i get with that code.
Code:
Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '$'
gillweb is offline  
Reply With Quote
Old 08-03-2011, 04:16 PM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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 />";
  }
?>
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 08-03-2011, 04:17 PM   #5 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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 />";
  }
?>
__________________
Thanks... Simon

Sex, Drugs & Linux Rules

Last edited by maeltar : 08-03-2011 at 05:32 PM.
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 08-03-2011, 04:35 PM   #6 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default

This did it! Thanks!
Quote:
Originally Posted by maeltar View Post
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 />";
  }
?>
gillweb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Parse error: parse error,syntex error unexpected ',' expectingT_STRING in my code tech Absolute Beginners 13 01-29-2013 10:00 AM
Parse error: syntax error, unexpected T_ECHO in -> regexp code on line 1 Torsten Advanced PHP Programming 3 02-03-2011 02:08 PM
Syntax error here why?.. codefreek Absolute Beginners 5 08-12-2008 06:39 PM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM


All times are GMT. The time now is 04:40 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design