0% found this document useful (0 votes)
2K views

Assignment 1: Set A

The document contains 3 sets of PHP coding questions and answers. Set A contains 2 questions - 1) a PHP script to track number of page visits using sessions and 2) a PHP script to allow changing web page preferences like font style, size, color etc using cookies across 3 pages. Set B contains 2 questions - 1) a login script with 3 attempts using sessions and 2) a form to accept employee details on one page and earnings on next to display total on third page using sessions. Set C contains a question to create a form to accept customer details, then product details and generate a bill displaying both using sessions.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Assignment 1: Set A

The document contains 3 sets of PHP coding questions and answers. Set A contains 2 questions - 1) a PHP script to track number of page visits using sessions and 2) a PHP script to allow changing web page preferences like font style, size, color etc using cookies across 3 pages. Set B contains 2 questions - 1) a login script with 3 attempts using sessions and 2) a form to accept employee details on one page and earnings on next to display total on third page using sessions. Set C contains a question to create a form to accept customer details, then product details and generate a bill displaying both using sessions.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment 1

-------------------------------------------------------------------------------------------------------------------------------

Set A
Q1)PHP script to keep track of number of times the web page has been access

Ans :

                              <?php

                                session_start();

                                if(isset($_SESSION['count']))

                                              $_SESSION['count']=$_SESSION['count']+1;

                                else

                                              $_SESSION['count']=1;

                                echo "<h3>This page is accessed</h3>".$_SESSION['count'];

?>

Q2)Write a PHP script to change the preference of your web page like font style, font, size, font color,
background color using cookie. Display selected settings on next page and actual implementation ( with
new settings) on third page.

Ans :

HTML file :
<html>

<body>

<form action="next.php" method="get">

Select font style :<input type = "text"    name = "s1"> <br>

Enter font size : <input type = "text" name = "s" ><br>

Enter font color : <input type = "text" name = "c"><br>


Enter background color :<input type    = "text" name = "b"><br>

<input type = "submit" value = "Next">

</form>

</body>

</html>

PHP file : next.php


<?php

echo "style is ".$_GET['s1']."<br>color is ".$_GET['c']."<br>Background color is ".$_GET['b']."<br>size is ".


$_GET['s'];

setcookie("set1",$_GET['s1'],time()+3600);

setcookie("set2",$_GET['c'],time()+3600);

setcookie("set3",$_GET['b'],time()+3600);

setcookie("set4",$_GET['s'],time()+3600);

?>

<html>

<body>

<form action="display.php">

<input type = "submit"    value = "OK">

</form>

</body>

</html>

PHP file : display.php


<?php
$style = $_COOKIE['set1'];

$color = $_COOKIE['set2'];

$size = $_COOKIE['set4'];

$b_color = $_COOKIE['set3'];

$msg = "Vrushali";

echo "<body bgcolor=$b_color>";

echo "<font color=$color size=$size>$msg";

echo "</font></body>";

?>

------------------------------------------------------------------------------------------------------------------------------------

Set B
1)Write a PHP script to accept username and password. If in the first three chances, username
and password entered is correct then display second form with “Welcome message”
otherwise display error message. [Use Session]

Ans :

Html file

<html>

<head>

</head>

<body>

<form method = "post" action = "sem6ass1setb1.php" >

Enter username <input type = "text" name="unm"></br>

Enter password <input type = "password" name ="pass"></br>

<input type="submit"    value="Login">


</body>

</html

Php File

<?php

                                session_start();

                                $nm=$_POST["unm"];

                                $ps=$_POST["pass"];

               

                                if($nm=="vrushali" && $ps == "Vrushali")

                {

                                        echo "Welcome ".$nm;

                }

                                else

                {

                 

                                        if($_SESSION['cnt']==3)

   {

            echo " You lost chanced";

            $SESSION['cnt'] = 0;

                   }

                                      else if($cnt<3)

                   {
                                            echo " you have chanced".$_SESSION['cnt'];

                                          $_SESSION['cnt'] = $_SESSION['cnt'] + 1;

                     }

             

                                }             

              

              

?>

2. Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On
second page accept earning (Basic, DA, HRA). On third page print Employee information (Eno,
Ename, Address, Basic, DA, HRA, Total) [ Use Session]

Ans :

Html File

<html>

<body>

      <form method="post"    action="earing.php">

        <b>

          Employee No : <input type="text" name="t1"><br>

          Emp Name        : <input type="text" name="t2"><br>

          Emp Add          : <input type="text" name="t3"><br>

          <input type="submit"    value="Save"><br>

    </form>

</body>

</html>
Earning File

<?php

        session_start();

        $_SESSION["eno"]=$_POST["t1"];

        $_SESSION["enm"]=$_POST["t2"];

        $_SESSION["add"]=$_POST["t3"];

          echo "<bR> Hello    ".$_SESSION["enm"]." Plz Fill your Earning Details ";

        echo    "<form method=post action='display.php'>";

        echo    " Basic      :-> <input type=text      name=t4><br>";

        echo    " DA            :-> <input type=text    name=t5><br>";

        echo    " HRA          :->    <input type=text        name=t6><br>";

            echo "<input type=submit      value='Display' > </form>";

      ?>

Display File

<?php

$a = $_POST["t4"];

$b = $_POST["t5"];

$c = $_POST["t6"];

        session_start();

            echo"<br><b> Emp Details      <b>";

            echo" Emp No      : ".$_SESSION["eno"]."<Br>";

            echo" Emp Name : ".$_SESSION["enm"]."<Br>";


            echo" Emp Add    : ".$_SESSION["add"]."<Br>";

            echo "<br><b>Earning Details <b>";

              echo"<br> Basic    --->".$_REQUEST["t4"]."<br>";

              echo"<br> DA          --->".$_REQUEST["t5"]."<br>";

              echo"<br> HRA        --->".$_REQUEST["t6"]."<br>";

              $sum = $a + $b + $c;

              echo"<br> Total Earning is : ".$sum;

          ?>

Set C
1. Crete a form to accept customer information ( Name, Addr, MobNo). Once the customer
information is accepted, accept product information in the next form (ProdName,
Qty,Rate). Generate the bill for the customer in the next form. Bill should contain the
customer information and the information of the products entered.

      Ans :

          HTML File
        <html>

<body>

      <form method="post"    action="product.php">

          Customer Name              : <input type="text" name="t1"><br>

          Customer Address        : <input type="text" name="t2"><br>

          Mobile No                      : <input type="text" name="t3"><br>


          <input type="submit"    value="Save"><br>

    </form>

</body>

</html>

          Product.php

    <?php

        session_start();

        $_SESSION["cnm"]=$_POST["t1"];

        $_SESSION["add"]=$_POST["t2"];

        $_SESSION["mob"]=$_POST["t3"];

          echo "<bR> Hello    ".$_SESSION["cnm"]." Plz Enter Your Product Details ";

        echo    "<form method=post action='display3.php'>";

        echo    " Product Name      :-> <input type=text      name=t4><br>";

        echo    " QTY                        :-> <input type=text    name=t5><br>";

        echo    " Rate                      :->    <input type=text        name=t6><br>";

            echo "<input type=submit      value='Display' > </form>";

      ?>

    

          Display3.php
<?php

$a = $_POST["t4"];

$b = $_POST["t5"];

$c = $_POST["t6"];

        session_start();

            echo"<br><b> Customer Details      </b><br>";

            echo" Customer Name        : ".$_SESSION["cnm"]."<Br>";

            echo" Customer Address : ".$_SESSION["add"]."<Br>";

            echo" Customer MobNO      : ".$_SESSION["mob"]."<Br>";

            echo "<br><b>Product Details </b><br>";

              echo"<br> Product Name    --->".$_REQUEST["t4"]."<br>";

              echo"<br> Qty                      --->".$_REQUEST["t5"]."<br>";

              echo"<br> Rate                    --->".$_REQUEST["t6"]."<br>";

              $total = $b*$c;

              echo"<br> Total : ".$total;

          ?>

You might also like