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


No comments:

Post a Comment