SPPU | pune university BCA SEM 3 PHP practical exam 2021 solved question

 1. Write a PHP script for the following: Design a form to accept two strings. Compare the two strings using both methods (= = operator &strcmp function). Append second string to the first string. Accept the position from the user; from where the characters from the first string are reversed. (Use radio buttons) 




Answer :

 

FILE NAME : one.php

<html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
    <div class="container">
        <form action="#" method="post">
            <div class="container p-3 my-3 border col-6 shadow">
                <div class="col">
                    <div class="col-md-4">
                        <label for="str1">FIRST STRING</label>
                    </div>
                    <div class="col">
                        <input type="text" name="str1" id="str1" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="str2">SECOND STRING</label>
                    </div>
                    <div class="col">
                        <input type="text" name="str2" id="str2" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="pos">STRING POSITION</label>
                    </div>
                    <div class="col">
                        <input type="text" name="pos" id="pos" class="form-control">
                    </div>
                </div><br>
                <div class="col ">
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="ch" value="1" id="checkbox1">
                        <label for="checkbox1"> COMPARE &nbsp;</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="ch" value="2" id="checkbox2">
                        <label for="checkbox2">CHECK WITH DATATYPE &nbsp;</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="ch" value="3" id="checkbox3">
                        <label for="checkbox3"> APPEND &nbsp;</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="ch" value="4" id="checkbox4">
                        <label for="checkbox4">POSSITION &nbsp;</label>
                    </div>
                </div>
                <div class="col">
                    <input type="submit" value="SUBMIT" name="SUBMIT" class=" btn btn-primary">
                    <input type="reset" value="RESTE" class="btn btn-danger">
                </div> 
            </div>
        </form>
    </div>
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </body>
</html>
<?php
if(isset($_POST['ch'])){
        
        $str1=$_POST['str1'];
        $str2=$_POST['str2'];
        $pos=$_POST['pos'];
        $ch=$_POST['ch'];
                                                                                                                       
        switch($ch)
        {
        case 1:
                if($str1==$str2)
                    echo"<script>swal('BOTH STRING ARE EQUAL!')</script>";
                else
                    echo"<script>swal('BOTH STRING ARE NOT EQUAL!')</script>";
        break;
        case 2:
            $s=strcmp($str1,$str2);
                if($s==0)
                        echo"<script>swal('BOTH STRING ARE EXAT EQUAL!')</script>";
                else
                        echo"<script>swal('BOTH STRING ARE NOT EQUAL!')</script>";
        break;
        case 3:
                echo "<script>swal('APPEND STRING1 AND STRING2 : $str1$str2')</script>";
        break;
        case 4: $len=strlen($str1)-$pos;
                $s=substr($str1,$pos,$len);
                $str4=strrev($s);
                echo"<script>swal('AFTER REVERSE : $str4')</script>";
        break;
        }
}
?>




2. Write PHP script to define an interface which has methods area(), volume(). Define constant PI. Create a class cylinder which implements this interface and calculate area and volume. 
Answer : 

FILE NAME : two.php
<html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
    <div class="container">
        <form action="#" method="post">
            <div class="container p-3 my-3 border col-6 shadow">
            <p>AREA OF CYLINDER</p>
                <div class="col">
                    <div class="col-md-4">
                        <label for="num1">RADIUS</label>
                    </div>
                    <div class="col">
                        <input type="number" name="num1" id="num1" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="num2">HEIGHT</label>
                    </div>
                    <div class="col">
                        <input type="number" name="num2" id="num2" class="form-control">
                    </div>
                </div><br>
                <P>VOLUME OF CYLINDER</P>
                <div class="col">
                    <div class="col-md-4">
                        <label for="num3">RADIUS</label>
                    </div>
                    <div class="col">
                        <input type="number" name="num3" id="num3" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="num4">HEIGHT</label>
                    </div>
                    <div class="col">
                        <input type="number" name="num4" id="num4" class="form-control">
                    </div>
                </div><br>
                <div class="col">
                    <input type="submit" value="SUBMIT" name="SUBMIT" class=" btn btn-primary">
                    <input type="reset" value="RESTE" class="btn btn-danger">
                </div> 
            </div>
        </form>
    </div>
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </body>
</html>
<?php
if(isset($_POST['SUBMIT'])){
    $num1=$_POST['num1'];
    $num2=$_POST['num2'];
    $num3=$_POST['num3'];
    $num4=$_POST['num4'];

    define("PI",3.14);
    $rad;
    $ht;
    $c;
    interface shape{
        public function area($r,$h);
        public function volume($r,$h);
    }
    class cylinder implements shape{
        public function area($r,$h){
            $GLOBALS['rad']=$r;
            $GLOBALS['ht']=$h;
            return $GLOBALS['area']= 2*PI*$GLOBALS['ht']*$GLOBALS['rad'];
        }
        public function volume($r,$h){
            return $GLOBALS['volume']= PI*$GLOBALS['ht']*$GLOBALS['rad']*$GLOBALS['rad'];
        }
    }
    $cy=new cylinder();
    $cy->area($num1,$num2);
    $cy->volume($num3,$num4);
    echo "<script>swal('AREA OF CYLINDER : ".$GLOBALS['area']." ".'\n\n'." VOLUME OF CYLINDER : ".$GLOBALS['volume']."')</script>";
}
?>




3. Write PHP program to create input form for Grocery that displays List of grocery items with checkboxes and create a bill according to list of items selected after clicking submit button.

ANSWER : 

FILE NAME : Three.1.html

<!DOCTYPE html>
<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <title>https://team-analytics.blogspot.com/</title>
</head>
<body>
<form action="grocery.php" method="post">
    <table>
        <thead>
            <tr>
                <th><h2>LIST OF GROCERY ITEMS<h2></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><img src="IMG/1.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="1"></td>
                <td>MILK</td>
                <td>80 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/2.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="2"></td>
                <td>CHEESE</td>
                <td>150 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/3.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="3"></td>
                <td>YOGURT</td>
                <td>90 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/4.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="4"></td>
                <td>PULSES</td>
                <td>55 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/5.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="5"></td>
                <td>CHOPPED TOMATOES</td>
                <td>95 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/6.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="6"></td>
                <td>SOUP</td>
                <td>125 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/7.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="7"></td>
                <td>FRUIT</td>
                <td>400 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/8.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="8"></td>
                <td>NUTS</td>
                <td>250 &#x20B9;</td>
            </tr>
            <tr>
                <td><img src="IMG/9.jpg" class="img-fluid"></td>
                <td><input type="checkbox" name="choice[]"  value="9"></td>
                <td>SPICE</td>
                <td>80 &#x20B9;</td>
            </tr>
        </tbody>
    </table><br>
    <input type="submit" value="ORDER" class="btn btn-success"> 
    <input type="reset" value="RESET" class="btn btn-danger">
</form>    
</body>
</html>


FILE NAME : grocery.php

<?php
if(isset($_POST['choice'])){
        $food=$_POST["choice"];
        $c=count($food);
        $price=0;
        echo "<table border='1'> <tr> <th>SR. No</th> <th>Product Name </th> <th>Price</th></tr>";        
        for($i=0; $i<$c;$i++){
            if($food[$i]==1){
                $price=$price+80;
                echo "<tr><td>1</td> <td>Milk</td> <td>80</td></tr>";
            }
            if($food[$i]==2){
                $price=$price+150;
                echo "<tr> <td>2</td> <td>Cheese</td> <td>150</td></tr>";
            }
            if($food[$i]==3){
                $price=$price+90;
                echo "<tr> <td>3</td> <td>Yogurt</td> <td>90</td></tr>";
            }
            if($food[$i]==4){
                $price=$price+55;
                echo "<tr> <td>4</td> <td>Pulses</td> <td>55</td></tr>";
            }
            if($food[$i]==5){
                $price=$price+95;
                echo "<tr> <td>5</td> <td>Chopped tomatoes</td> <td>95</td></tr>";
            }
            if($food[$i]==6){
                $price=$price+125;
                echo "<tr> <td>6</td> <td>Soup</td> <td>125</td></tr>";
            }
            if($food[$i]==7){
                $price=$price+400;
                echo "<tr> <td>7</td> <td>Fruit</td> <td>400</td></tr>";
            }
            if($food[$i]==8){
                $price=$price+250;
                echo "<tr> <td>8</td> <td> Nuts</td> <td>250</td></tr>";
            }
            if($food[$i]==9){
                $price=$price+80;
                echo "<tr> <td>9</td> <td>spices</td> <td>80</td></tr>";
            }
        }
        echo "<tr>  <td colspan='2'>Total Pay</td> <td>$price</td></tr>";
    }
else{
    echo "Please choose something...!";
}

echo "</table>";

?>





4. Write a PHP script to create a login form with a username and password. Once the user logs in, the second form should be displayed to accept user details (name, city, phoneno). If the user doesn’t enter information within a specified time limit, expire his session and give a warning.
Answer : 
File Name : 4.php

<?php
session_start();
if(isset($_POST['username'])){
    if($_REQUEST['username']=='saurabh' && $_REQUEST['password']=='saurabh'){
        $_SESSION['time'] =time()+12;
        $_SESSION['time1'] =time()+10;
        echo "<script> location.href='4.1.php' </script>";
    }
}
?>
<html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
    <div class="container">
        <form action="#" method="post">
            <div class="container p-3 my-3 border col-4 shadow">
                <div class="col">
                    <div class="col-md-8">
                    <label for="username"><i class="fas fa-user"></i> USERNAME </label>
                    </div>
                    <div class="col">
                        <input type="text" name="username" id="username" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-8">
                        <label for="password"><i class="fas fa-unlock-alt"></i> PASSWORD </label>
                    </div>
                    <div class="col">
                        <input type="password" name="password" id="password" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <p class="text-right">Forgot Password</p>
                </div>
                <div class="col">
                    <input type="submit" value="LOGIN"  class=" btn btn-primary">
                    <input type="reset" value="RESET" class="btn btn-danger">
                </div> 
            </div>
        </form>
    </div>
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </body>
</html>


FILE NAME : 4.1.php

<?php
session_start();
if ($_SESSION['time'] > time()){
?>
<html>
    <head>
    <meta http-equiv="refresh" content="11">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
    <div class="container">
        <form action="#" method="post">
            <div class="container p-3 my-3 border col-4 shadow">
                <div class="col">
                    <div class="col-md-4">
                        <label for="name">NAME</label>
                    </div>
                    <div class="col">
                        <input type="text" name="name" id="name" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="city">CITY</label>
                    </div>
                    <div class="col">
                        <input type="text" name="city" id="city" class="form-control">
                    </div>
                </div>
                <div class="col">
                    <div class="col-md-4">
                        <label for="pno">PHONENO</label>
                    </div>
                    <div class="col">
                        <input type="number" name="pno" id="pno" class="form-control">
                    </div>
                </div><br>
                <div class="col">
                    <input type="submit" value="SUBMIT" name="SUBMIT" class=" btn btn-primary">
                    <input type="reset" value="RESTE" class="btn btn-danger">
                </div> 
            </div>
        </form>
    </div>
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </body>
</html>
<?php
}else{
    session_unset();
    session_destroy();
    echo "<script> location.href='4.php' </script>";
}
if( $_SESSION['time1'] < time()){
    echo"<script>swal({title: 'Session Destroy...!',text: 'try another time....!',icon: 'warning',});</script>";
}
if(isset($_POST['name'])){
    if($_POST['name']!=NULL && $_POST['city']!=NULL && $_POST['pno']!=NULL){
        echo"<script>swal({title: 'Good job!',text: 'Data Inserted Successfully!',icon: 'success',});</script>";
    }
}
?>





5. Write a PHP script to keep track of number of times the web page has been accessed.



Answer :  

FILE  NAME : five.php
<html>
    <head>
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </body>
</html>

<?php
    session_start();
    if(isset($_SESSION['count'])){
        $_SESSION['count']=$_SESSION['count']+1;
    }else{
        $_SESSION['count']=1;
    }
    echo"<script>swal('THIS PAGE IS ACCESSED ".$_SESSION['count']." TIMES ')</script>";
?>




6. Consider the following entities and their relationships Emp (emp_no,emp_name,address,phone,salary) Salary(em_pno, Basic, HR, TA, DA) Dept (dept_no,dept_name,location) Emp-Dept are related with one-many relationship Create a RDB for the above and solve following Using above database. write a PHP script which will print a salary statement for specified emp_no with his details.







ANSWER :
FILE NAME : six.php

<html>
    <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <title>https://team-analytics.blogspot.com/</title>
    </head>
    <body>
    <div class="container">
        <form action="#" method="post">
            <div class="container p-3 my-3 border col-6 shadow">
                <div class="col">
                    <div class="col-md-4">
                        <label for="num">EMPLOYEE NO.</label>
                    </div>
                    <div class="col">
                        <input type="number" name="num" id="num" class="form-control">
                    </div>
                </div><br>
                <div class="col">
                    <input type="submit" value="SUBMIT" name="SUBMIT" class=" btn btn-primary">
                    <input type="reset" value="RESTE" class="btn btn-danger">
                </div> 
            </div>
        </form>
    </div>
    </body>
</html>
<?php
    if(isset($_POST['num'])){
        $num = $_POST['num'];
        $conn = mysqli_connect("localhost","root","","test_db");
        $emp = "SELECT * FROM Salary s ,Emp e ,Dept d WHERE e.emp_no=d.dept_no AND e.emp_no=s.emp_pno AND emp_no=$num ";
        $res = mysqli_query($conn,$emp);
        if(mysqli_num_rows($res)>0){
            while($row = mysqli_fetch_assoc($res)){     
?>
<div class="col-5">
<h2>SALARY STATEMENT</h2><HR>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>EMP ID : </th><td><?php echo $row['emp_no']?></td>
                <th>EMP NAME : </th><td><?php echo $row['emp_name']?></td>
            </tr>
            <tr>
                <th>Location : </th><td><?php echo $row['address']?></td>
                <th>DEPARTMENT : </th><td><?php echo $row['dept_name']?></td>
            </tr>
            <tr>
                <th>SR.NO</th>
                <th>Earning</th>
                <th>Rate</th>
                <th>Amount</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1.</td> <td colspan="2">BASIC PAY</td><td><?php echo $row['Basic'] . "&#x20B9;"?></td>
            </tr>

            <tr>
            <td>2.</td> <td colspan="2">HR</td><td colspan="2"><?php echo $row['HR'] . "&#x20B9;"?></td>
            </tr>

            <tr>
            <td>3.</td> <td colspan="2">Traveling Allowance</td><td><?php echo $row['TA'] . "&#x20B9;"?></td>
            </tr>
            <tr>
            <td>4.</td> <td colspan="2">DA</td><td><?php echo $row['DA'] . "&#x20B9;"?></td>
            </tr>
            <tr>
            <td>5.</td> <td colspan="2">Other Allowance</td><td> 100 &#x20B9;</td>
            </tr>
            <tr>
            <td colspan="3">Total RS.</td> <td><?php  echo $A   = $row['Basic']+$row['HR']+$row['TA']+$row['DA']+100 ?> &#x20B9;</td>
            </tr>
        </tbody>
    </table>
</div>
<?php 
            }
        }
    
    }
?>
SPPU | pune university BCA SEM 3 PHP practical exam 2021 solved question SPPU | pune university BCA SEM  3 PHP practical exam 2021 solved question Reviewed by technical_saurabh on April 28, 2021 Rating: 5

No comments:

Powered by Blogger.