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

What's hot (20)

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Php string function
Php string function
Ravi Bhadauria
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
Geshan Manandhar
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Basic PHP
Basic PHP
Todd Barber
 
PHP variables
PHP variables
Siddique Ibrahim
 
Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
Php and MySQL
Php and MySQL
Tiji Thomas
 
Operators in PHP
Operators in PHP
Vineet Kumar Saini
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Data Types In PHP
Data Types In PHP
Mark Niebergall
 
Basic of PHP
Basic of PHP
Nisa Soomro
 
PHP Basic
PHP Basic
Yoeung Vibol
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
Kana Natsuno
 
Php
Php
mohamed ashraf
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
O'Reilly Media
 
Intermediate PHP
Intermediate PHP
Bradley Holt
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Php mysql
Php mysql
Alebachew Zewdu
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
Geshan Manandhar
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
Kana Natsuno
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
O'Reilly Media
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 

Viewers also liked (20)

Php Simple Xml
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
Php String And Regular Expressions
mussawir20
 
Php Sq Lite
Php Sq Lite
mussawir20
 
Database Design Process
Database Design Process
mussawir20
 
Json
Json
mussawir20
 
Javascript
Javascript
mussawir20
 
Oop in php_tutorial
Oop in php_tutorial
Gregory Hanis
 
Hash
Hash
mussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Object
Object
mussawir20
 
Php Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Optimizing spatial database
Optimizing spatial database
Ishraq Al Fataftah
 
Php Using Arrays
Php Using Arrays
mussawir20
 
Php Error Handling
Php Error Handling
mussawir20
 
Rest Essentials
Rest Essentials
Sergey Podolsky
 
Spatial index(2)
Spatial index(2)
Mohsen Rashidian
 
Chapter 3 Consumer Behaviour
Chapter 3 Consumer Behaviour
provost33
 
Theory Of Consumer Behavior
Theory Of Consumer Behavior
Kishore Raveendran
 
Introduction To Macro Economics
Introduction To Macro Economics
Saurabh Goel
 
Microeconomics: Utility and Demand
Microeconomics: Utility and Demand
Manuel Salas-Velasco, University of Granada, Spain
 
Ad

Similar to Php Calling Operators (20)

Php Crash Course
Php Crash Course
mussawir20
 
P H P Part I, By Kian
P H P Part I, By Kian
phelios
 
Introduction to php
Introduction to php
sagaroceanic11
 
What Is Php
What Is Php
AVC
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Php
Php
Rajkiran Mummadi
 
php programming.pptx
php programming.pptx
rani marri
 
PHP MySQL
PHP MySQL
Md. Sirajus Salayhin
 
Php Chapter 1 Training
Php Chapter 1 Training
Chris Chubb
 
PHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
PHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
PHP Basics
PHP Basics
Saraswathi Murugan
 
Introduction To Lamp
Introduction To Lamp
Amzad Hossain
 
PHP Presentation
PHP Presentation
Nikhil Jain
 
Php Training
Php Training
adfa
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Php & my sql
Php & my sql
Norhisyam Dasuki
 
Php-Continuation
Php-Continuation
lotlot
 
Learn PHP Basics
Learn PHP Basics
McSoftsis
 
Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
Php Crash Course
Php Crash Course
mussawir20
 
P H P Part I, By Kian
P H P Part I, By Kian
phelios
 
What Is Php
What Is Php
AVC
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
php programming.pptx
php programming.pptx
rani marri
 
Php Chapter 1 Training
Php Chapter 1 Training
Chris Chubb
 
Introduction To Lamp
Introduction To Lamp
Amzad Hossain
 
PHP Presentation
PHP Presentation
Nikhil Jain
 
Php Training
Php Training
adfa
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Php-Continuation
Php-Continuation
lotlot
 
Learn PHP Basics
Learn PHP Basics
McSoftsis
 
Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
Ad

More from mussawir20 (17)

Php Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Php Oop
Php Oop
mussawir20
 
Php My Sql
Php My Sql
mussawir20
 
Php File Operations
Php File Operations
mussawir20
 
Php Basic Security
Php Basic Security
mussawir20
 
Javascript Oop
Javascript Oop
mussawir20
 
Html
Html
mussawir20
 
Object Range
Object Range
mussawir20
 
Date
Date
mussawir20
 
Prototype js
Prototype js
mussawir20
 
Template
Template
mussawir20
 
Class
Class
mussawir20
 
Element
Element
mussawir20
 
Position
Position
mussawir20
 
Timedobserver
Timedobserver
mussawir20
 
Enumerable
Enumerable
mussawir20
 
Event
Event
mussawir20
 

Recently uploaded (20)

Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 

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>