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 :-
   

No comments:

Post a Comment