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

Related Post :-

php for loop

css id selector

html address tag

Comments

Popular posts from this blog

What Is CSS Text Color in 2026

CSS Padding Property Explained

CSS Outline Color Property in 2026