SlideShare a Scribd company logo
calling all operator
FORM A form provides a medium of interface for the client and the server to interact with each other. A form allow the user to actually input raw data into the application. A form consists of the following attributes: Action- specifies the Uniform Resource Locator(URL) that will process the form data and send the feedback.  Method- specifies the way the information is to be sent to the URL User (web browser) Web Server Enter data and the data are sent to Php script engine Passes data Process the data Give response or output
There are two common methods for passing data from one script to another: GET and POST.  The GET method specifies the web browser to send all the user information as part of the URL. In this method, a ? is added at the end of the URL. This ? Indicates the ending of the URL and the beginning of the form information. The POST method specifies the web browser that all the user information is sent through the body of the HTTP request.
This example contains two scripts, one containing an HTML form (named form.htm) and the other containing the form processing logic (message.php).  Here's form.htm:   <html> <head> </head> <body> <form action=&quot;message.php&quot; method=&quot;post&quot;>  Enter your message: <input type=&quot;text&quot; name=&quot;msg&quot; size=&quot;30&quot;>  <input type=&quot;submit&quot; value=&quot;Send&quot;>  </form>  </body> </html>
Here the message.php: <html>  <head></head> <body>  <?php  // retrieve form data  $input  =  $_POST [ 'msg' ];  // use it  echo  &quot;You said: <i>$input</i>&quot; ;  ?>  </body>  </html>
operator An  operator  is a symbol that specifies a particular action in an expression.
 
Comparison operator <?php  /* define some variables */ $mean  =  9 ;  $median  =  10 ;  $mode  =  9 ;  // less-than operator  // returns true if left side is less than right  // returns true here  $result  = ( $mean  <  $median );  print  &quot;result is $result<br />&quot; ;
// greater-than operator  // returns true if left side is greater than right  // returns false here  $result  = ( $mean  >  $median );  print  &quot;result is $result<br />&quot; ;  // less-than-or-equal-to operator  // returns true if left side is less than or equal to right  // returns false here  $result  = ( $median  <=  $mode );  print  &quot;result is $result<br />&quot; ;
// greater-than-or-equal-to operator  // returns true if left side is greater than or equal to right  // returns true here  $result  = ( $median  >=  $mode );  print  &quot;result is $result<br />&quot; ;  // equality operator  // returns true if left side is equal to right  // returns true here  $result  = ( $mean  ==  $mode );  print  &quot;result is $result<br />&quot; ;
The result of a comparison test is always Boolean: either true (1) or false   (0 does not print anything) // not-equal-to operator  // returns true if left side is not equal to right  // returns false here  $result  = ( $mean  !=  $mode );  print  &quot;result is $result<br />&quot; ;  // inequality operator  // returns true if left side is not equal to right  // returns false here  $result  = ( $mean  <>  $mode );  print  &quot;result is $result&quot; ;  ?>
=== operator <?php  /* define two variables */ $str  =  '10' ;  $int  =  10 ;  /* returns true, since both variables contain the same value */  $result  = ( $str  ==  $int );  print  &quot;result is $result<br />&quot; ;  /* returns false, since the variables are not of the same type even though they have the same value */  $result  = ( $str  ===  $int );  print  &quot;result is $result<br />&quot; ;   /* returns true, since the variables are the same type and value */  $anotherInt  =  10 ;  $result  = ( $anotherInt  ===  $int );  print  &quot;result is $result&quot; ;  ?>
Logical operator Four logical operator: AND, OR, XOR, NOT <?php  /* define some variables */ $auth  =  1 ;  $status  =  1 ;  $role  =  4 ;  /* logical AND returns true if all conditions are true */  // returns true  $result  = (( $auth  ==  1 ) && ( $status  !=  0 ));  print  &quot;result is $result<br />&quot; ;
/* logical OR returns true if any condition is true */  // returns true  $result  = (( $status  ==  1 ) || ( $role  <=  2 ));  print  &quot;result is $result<br />&quot; ;  /* logical NOT returns true if the condition is false and vice-versa */  // returns false  $result  = !( $status  ==  1 );  print  &quot;result is $result<br />&quot; ;  /* logical XOR returns true if either of two conditions are true, or returns false if both conditions are true */  // returns false  $result  = (( $status  ==  1 ) xor ( $auth  ==  1 ));  print  &quot;result is $result<br />&quot; ;  ?>
Conditional statement a conditional statement allows you to test whether a specific condition is true or false, and perform different actions on the basis of the result.  if The if conditional is one of the most commonplace constructs of any mainstream programming language, offering a convenient means for conditional code execution. The syntax is: if ( expression ) { statement }
Example: <html>  <head></head> <body>  <form action=&quot;ageist.php&quot; method=&quot;post&quot;>  Enter your age: <input name=&quot;age&quot; size=&quot;2&quot;>  </form>  </body>  </html>
ageist.php <html>  <head></head> <body>  <?php  // retrieve form data  $age  =  $_POST [ 'age' ];  // check entered value and branch  if ( $age  >=  21 ) {       echo  'Come on in, we have alcohol and music awaiting you!' ;  }  if ( $age  <  21 ) {       echo  &quot;You're too young for this club, come back when you're a little older&quot; ;  }  ?>  </body>  </html>
if-else construct, used to define a block of code that gets executed when the conditional expression in the if() statement evaluates as false.  The if-else construct looks like this:  if (condition) {      do this!      }  else {      do this!  }
Example: <html>  <head></head> <body>  <?php  // retrieve form data  $age  =  $_POST [ 'age' ];  // check entered value and branch  if ( $age  >=  21 ) {      echo  'Come on in, we have alcohol and music awaiting you!' ;      }  else {      echo  &quot;You're too young for this club, come back when you're a little older&quot; ;  }  ?>  </body>  </html>
Ternary operator represented by a question mark (?). This operator, which lets you make your conditional statements almost unintelligible, provides shortcut syntax for creating a single-statement if-else block.  <?php  if ( $numTries  >  10 ) {        $msg  =  'Blocking your account...' ;      }  else {       $msg  =  'Welcome!' ;  }  ?>
You could also do this, which is equivalent  <?php  $msg  =  $numTries  >  10  ?  'Blocking your account...'  :  'Welcome!' ;  ?>
Nested if or <?php  if ( $day  ==  'Thursday' ) {      if ( $time  ==  '0800' ) {          if ( $country  ==  'UK' ) {               $meal  =  'bacon and eggs' ;          }      }  }  ?>   <?php  if ( $day  ==  'Thursday'  &&  $time  ==  '0800'  &&  $country  ==  'UK' ) {       $meal  =  'bacon and eggs' ;  }  ?>
<html>  <head></head> <body>  <h2>Today's Special</h2>  <p>  <form method=&quot;get&quot; action=&quot;cooking.php&quot;>  <select name=&quot;day&quot;>  <option value=&quot;1&quot;>Monday/Wednesday  <option value=&quot;2&quot;>Tuesday/Thursday  <option value=&quot;3&quot;>Friday/Sunday  <option value=&quot;4&quot;>Saturday  </select>  <input type=&quot;submit&quot; value=&quot;Send&quot;>  </form>  </body>  </html>
<html> <head></head> <body>  <?php  // get form selection  $day  =  $_GET [ 'day' ];  // check value and select appropriate item  if ( $day  ==  1 ) {       $special  =  'Chicken in oyster sauce' ;      }  elseif ( $day  ==  2 ) {       $special  =  'French onion soup' ;      }  elseif ( $day  ==  3 ) {       $special  =  'Pork chops with mashed potatoes and green salad' ;      }  else {       $special  =  'Fish and chips' ;  }  ?>  <h2>Today's special is:</h2>  <?php  echo  $special ;  ?>  </body> </html>

More Related Content

Php Calling Operators

  • 2. FORM A form provides a medium of interface for the client and the server to interact with each other. A form allow the user to actually input raw data into the application. A form consists of the following attributes: Action- specifies the Uniform Resource Locator(URL) that will process the form data and send the feedback. Method- specifies the way the information is to be sent to the URL User (web browser) Web Server Enter data and the data are sent to Php script engine Passes data Process the data Give response or output
  • 3. There are two common methods for passing data from one script to another: GET and POST. The GET method specifies the web browser to send all the user information as part of the URL. In this method, a ? is added at the end of the URL. This ? Indicates the ending of the URL and the beginning of the form information. The POST method specifies the web browser that all the user information is sent through the body of the HTTP request.
  • 4. This example contains two scripts, one containing an HTML form (named form.htm) and the other containing the form processing logic (message.php). Here's form.htm: <html> <head> </head> <body> <form action=&quot;message.php&quot; method=&quot;post&quot;> Enter your message: <input type=&quot;text&quot; name=&quot;msg&quot; size=&quot;30&quot;> <input type=&quot;submit&quot; value=&quot;Send&quot;> </form> </body> </html>
  • 5. Here the message.php: <html> <head></head> <body> <?php // retrieve form data $input = $_POST [ 'msg' ]; // use it echo &quot;You said: <i>$input</i>&quot; ; ?> </body> </html>
  • 6. operator An operator is a symbol that specifies a particular action in an expression.
  • 7.  
  • 8. Comparison operator <?php /* define some variables */ $mean = 9 ; $median = 10 ; $mode = 9 ; // less-than operator // returns true if left side is less than right // returns true here $result = ( $mean < $median ); print &quot;result is $result<br />&quot; ;
  • 9. // greater-than operator // returns true if left side is greater than right // returns false here $result = ( $mean > $median ); print &quot;result is $result<br />&quot; ; // less-than-or-equal-to operator // returns true if left side is less than or equal to right // returns false here $result = ( $median <= $mode ); print &quot;result is $result<br />&quot; ;
  • 10. // greater-than-or-equal-to operator // returns true if left side is greater than or equal to right // returns true here $result = ( $median >= $mode ); print &quot;result is $result<br />&quot; ; // equality operator // returns true if left side is equal to right // returns true here $result = ( $mean == $mode ); print &quot;result is $result<br />&quot; ;
  • 11. The result of a comparison test is always Boolean: either true (1) or false (0 does not print anything) // not-equal-to operator // returns true if left side is not equal to right // returns false here $result = ( $mean != $mode ); print &quot;result is $result<br />&quot; ; // inequality operator // returns true if left side is not equal to right // returns false here $result = ( $mean <> $mode ); print &quot;result is $result&quot; ; ?>
  • 12. === operator <?php /* define two variables */ $str = '10' ; $int = 10 ; /* returns true, since both variables contain the same value */ $result = ( $str == $int ); print &quot;result is $result<br />&quot; ; /* returns false, since the variables are not of the same type even though they have the same value */ $result = ( $str === $int ); print &quot;result is $result<br />&quot; ; /* returns true, since the variables are the same type and value */ $anotherInt = 10 ; $result = ( $anotherInt === $int ); print &quot;result is $result&quot; ; ?>
  • 13. Logical operator Four logical operator: AND, OR, XOR, NOT <?php /* define some variables */ $auth = 1 ; $status = 1 ; $role = 4 ; /* logical AND returns true if all conditions are true */ // returns true $result = (( $auth == 1 ) && ( $status != 0 )); print &quot;result is $result<br />&quot; ;
  • 14. /* logical OR returns true if any condition is true */ // returns true $result = (( $status == 1 ) || ( $role <= 2 )); print &quot;result is $result<br />&quot; ; /* logical NOT returns true if the condition is false and vice-versa */ // returns false $result = !( $status == 1 ); print &quot;result is $result<br />&quot; ; /* logical XOR returns true if either of two conditions are true, or returns false if both conditions are true */ // returns false $result = (( $status == 1 ) xor ( $auth == 1 )); print &quot;result is $result<br />&quot; ; ?>
  • 15. Conditional statement a conditional statement allows you to test whether a specific condition is true or false, and perform different actions on the basis of the result. if The if conditional is one of the most commonplace constructs of any mainstream programming language, offering a convenient means for conditional code execution. The syntax is: if ( expression ) { statement }
  • 16. Example: <html> <head></head> <body> <form action=&quot;ageist.php&quot; method=&quot;post&quot;> Enter your age: <input name=&quot;age&quot; size=&quot;2&quot;> </form> </body> </html>
  • 17. ageist.php <html> <head></head> <body> <?php // retrieve form data $age = $_POST [ 'age' ]; // check entered value and branch if ( $age >= 21 ) {      echo 'Come on in, we have alcohol and music awaiting you!' ; } if ( $age < 21 ) {      echo &quot;You're too young for this club, come back when you're a little older&quot; ; } ?> </body> </html>
  • 18. if-else construct, used to define a block of code that gets executed when the conditional expression in the if() statement evaluates as false. The if-else construct looks like this: if (condition) {     do this!     } else {     do this! }
  • 19. Example: <html> <head></head> <body> <?php // retrieve form data $age = $_POST [ 'age' ]; // check entered value and branch if ( $age >= 21 ) {     echo 'Come on in, we have alcohol and music awaiting you!' ;     } else {     echo &quot;You're too young for this club, come back when you're a little older&quot; ; } ?> </body> </html>
  • 20. Ternary operator represented by a question mark (?). This operator, which lets you make your conditional statements almost unintelligible, provides shortcut syntax for creating a single-statement if-else block. <?php if ( $numTries > 10 ) {       $msg = 'Blocking your account...' ;     } else {      $msg = 'Welcome!' ; } ?>
  • 21. You could also do this, which is equivalent <?php $msg = $numTries > 10 ? 'Blocking your account...' : 'Welcome!' ; ?>
  • 22. Nested if or <?php if ( $day == 'Thursday' ) {     if ( $time == '0800' ) {         if ( $country == 'UK' ) {              $meal = 'bacon and eggs' ;         }     } } ?> <?php if ( $day == 'Thursday' && $time == '0800' && $country == 'UK' ) {      $meal = 'bacon and eggs' ; } ?>
  • 23. <html> <head></head> <body> <h2>Today's Special</h2> <p> <form method=&quot;get&quot; action=&quot;cooking.php&quot;> <select name=&quot;day&quot;> <option value=&quot;1&quot;>Monday/Wednesday <option value=&quot;2&quot;>Tuesday/Thursday <option value=&quot;3&quot;>Friday/Sunday <option value=&quot;4&quot;>Saturday </select> <input type=&quot;submit&quot; value=&quot;Send&quot;> </form> </body> </html>
  • 24. <html> <head></head> <body> <?php // get form selection $day = $_GET [ 'day' ]; // check value and select appropriate item if ( $day == 1 ) {      $special = 'Chicken in oyster sauce' ;     } elseif ( $day == 2 ) {      $special = 'French onion soup' ;     } elseif ( $day == 3 ) {      $special = 'Pork chops with mashed potatoes and green salad' ;     } else {      $special = 'Fish and chips' ; } ?> <h2>Today's special is:</h2> <?php echo $special ; ?> </body> </html>