Friday, March 29, 2024

PHP if else statements


  PHP  if else statements

PHP  if else statements


Information :-

Code inside if block execute once's when condition is True  and

code inside the else block execute once condition false.


Syntax :-

 statement ;

if (condition)

{

statement;

statement;

}

else

{

statement;

statement;

}


Example:-

<html>
    <head>
        <title>php if else satatement program</title>
    </head>
    <body>

        <h2>php if else statement</h2>
        <?php
        $age=18;
       
        if($age>18)
        {
            echo"  student is Eligible";
        }
        else
        {
            echo" student is no Eligible";
        }
        ?>
       
</body>
    </html>


 Output:-

PHP  if else statement program  /output

Example :-

Q. Student result display 

<html>
    <head>
    <title>student marks</title>
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
    <body class="bg-primary">
        <center>
        <div class="col-md-4 mt-5 bg-white shadow-lg mx-auto p-2" >
        <form action="student-marks.php" method="get">
         <h2>Student Result</h2>
        <input type="text" name="nm"placeholder="student name" required> <br>
         
            <input type="number" name="mr" placeholder="Marathi" required> <br>
           <input type="number" name="eg" placeholder="english" required><br>
            <input type="number" name="mt" placeholder="mathematics" required><br>
            <input type="number" name="his" placeholder="history" required></br><br>
            <input type="submit" value="show result" name="b1"><br>

        </form>

                <?php
                if(isset($_GET["b1"]))
                {
                /* input type */
            $name= $_GET['nm'];
            $s1=$_GET['mr'];
            $s3=$_GET['eg'];
            $s4=$_GET['mt'];
            $s5=$_GET['his'];
            /* operation */
            $total=$s1+$s3+$s4+$s5;
            $per=$total/4;
            /* output*/
            echo "hi..." .$name;
            echo "<br> Total Mark =" .$total;
            echo "<br> percentage=".$per;
                     if($s1>=35&& $s3>=35&& $s4>=35 &&$s5>=35)
                     {
                        $Remark="Pass";
                     }
                     else
                     {
                        $Remark="fail";

                     }
                   
                     
                     echo "<br>Remark=" .$Remark;
                }
                ?>
                </div>
            <center>
            </body>

    </html>


Output:- 

PHP  if else statement program  /output


Read more :-

PHP Introduction

PHP Variables

PHP Data Types

PHP Operators


Saturday, March 9, 2024

PHP if Statements

PHP if statements


PHP if statements


if statements inside they if block is execute the once them codition is true.

Syntax :-
      statement ;
          if (condition) 
        
         {
          /*block of code */

         }

PHP if Statements 
 
Example :-
Q] Accept name of student from user and show student name in same page.

<html>
   
    <form action="collect_data_student.php"
method="get">
    <label> Enter name</label><br>    
    <input type="text" name="snm" require>
<br><br>
    <input type="submit" value="show" name="b1"
>
   <?php
        if (isset($_GET["b1"]))
        {
                $name=$_GET["snm"];
                echo " <br> hi :-". $name;
        }
   ?>

</form>
</html> 


PHP if Statements 
Output :-

php if statement /output

Example 

2]   Accept price and amount the user from and calculate bill .price and bill amount person 
      get 10% discount of total bill amount 5000. 


    <html>
        <head>
    <title>calculate the bile </title>
</head>
    <form action="bill.php" method="get">
        <label>Price</label>
        <input type="number" name="price"
required><br><Br>

        <label>quantity</label>
        <input type ="number" name="quantity"
required><br><br>
        <input type="submit" value="show"
name="b1"required>
</form>

<?php
if(isset($_GET["b1"]))
{
    /*input */
    $pr=$_GET["price"];
    $qty=$_GET["quantity"];

    /* operator */
    $bill=$pr*$qty;
    $discount= ($bill>5000)?10:0;
    $disamt=($bill*$discount)/100;
    $tbill=$bill-$disamt;
    /* output*/
    echo" price=" .$pr;
    echo "<br>quantity =" .$qty;
    echo "<br>Bill=" .$bill;
    echo "<br> discount =" .$discount;
    echo "<br>discount amount =". $disamt;
    echo "<br>total bill = ". $tbill;
}
?>
</html>




output :-

php if statement use program/output

READ MORE :-
   

Wednesday, March 6, 2024

PHP Increment/ Decrement operators


PHP Increment/ Decrement operators

PHP Increment/ Decrement operators



Increment/Decrement Operators :-

  • Increment (++)
  • Decrement (--)

PHP Increment/ Decrement operators

Example :-


<?php
// Example of increment operator
$a = 5;
echo "Original value of \$a: $a <br>";

$a++; // Increment $a by 1
echo "Value of \$a after incrementing: $a <br>";

// Example of decrement operator
$b = 10;
echo "Original value of \$b: $b <br>";

$b--; // Decrement $b by 1
echo "Value of \$b after decrementing: $b <br>";
?>

PHP Increment/ Decrement operators

Output :-

php increment /Decrement operators example/output



READ MORE

PHP String Operators

 PHP String Operators 

PHP string operators



PHP String Operators:

  • Concatenation (.)
  • Concatenation assignment (.=)


PHP String Operators:

Example :-

<?php
// Concatenation operator (.)
$string1 = "Hello";
$string2 = "World";

$result = $string1 . " " . $string2;

echo $result;
?>
PHP String Operators

Output :-

PHP String Operators EXAMPLE /Output


READ MORE

Tuesday, March 5, 2024

PHP logical operators

   PHP logical operators 

PHP logical operators



Logical Operators:

  • AND (&& or and)
  • OR (|| or or)
  • NOT (! or not)
  • XOR (exclusive OR) (xor)

 PHP logical operators 

Example :-


<?php
$a=10;
$b=5;
$c=20;
$d=20;
var_dump(($a<$c)&&($c==$d)&&($b<$c));//true
var_dump(!(($a<$c)&&($c==$d)&&($b<$c)));//false
var_dump(($a>$d)||($b<$c));//true
?>

 logical operators php

Output

logical operators php/output









READ MORE

PHP Arithmetic Operators

 PHP Arithmetic Operators 

PHP Arithmetic operators


Arithmetic Operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)
  • Exponentiation (**)

Arithmetic Operators php

Example :-

<?php
$no1 = 20;
$no2 =5;
//ope
$add =$no1 + $no2;
$sub= $no1 - $no2;
$multi= $no1 *$no2;
$divi =$no1 / $no2;
$remainder = $no1 % $no2;

//out
echo "Addition =".$add;
echo"<br>subtraction =".$sub;
echo "<br> multiplication =".$multi;
echo "<br> division=".$divi;
echo"<br> remainder = ".$remainder;
?>

Arithmetic Operators php

Output :-

Addition =25
subtraction =15
multiplication =100
division=4
remainder = 0

READ MORE

PHP introduction

PHP variable

PHP operators

PHP Data type

PHP logical operators

PHP Arithmetic Operators

PHP Assignment Operators

PHP string operators

PHP While LOOP

PHP for loop