Wednesday, January 8, 2025

WT-II Assignment-4

 ASSIGNMENT NO. 4: AJAX

 Set A
1. Write AJAX program to read contact.dat file and print the contents of the file in a tabular format when the user clicks on print button. Contact.dat file should contain srno, name, residence number, mobile number, Address. [Enter at least 3 record in contact.dat file]

Solution:-

 

2. Write AJAX program where the user is requested to write his or her name in a text box, and the server keeps sending back responses while the user is typing. If the user name is not entered then the message displayed will be, “Stranger, please tell me your name!”. If the name is Rohit, Virat, Dhoni, Ashwin or Harbhajan , the server responds with “Hello, master <user name>!”. If the name is anything else, the message will be “<user name>, I don’t know you!”.

Solution:-

 


Set B
1. Create TEACHER table as follows TEACHER(tno, tname, qualification, salary). Write Ajax program to select a teachers name and print the selected teachers details.

Solution:-

 


CUSTOMER (cno, cname, city) and  ORDER(ono, odate, shipping address)2. Write Ajax program to print Order details by selecting a Customer’s name. Create table Customer and Order as follows with 1 : M cardinality CUSTOMER (cno, cname, city) and  ORDER(ono, odate, shipping address)

Solution:-

 


Set C
1. Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like google suggestions. Hint create array of suggestions and matching string will be displayed)

Solution:-

 


2. Write Ajax program to get book details from XML file when user select a book name. Create XML file for storing details of book(title, author, year, price).

Solution:-

 

 

 

WT-II Assignment -3

  ASSIGNMENT NO. : 3 JAVASCRIPT and jquery


SET A:
1) Write a javascript to display message ‘Exams are near, have you started preparing for?’ using alert, prompt and confirm boxes. Accept proper input from user and display messages accordingly.

Solution:-

<html>
  <body>
    <h1>javascript Promt</h1>
    <button onclick="fun()">Click Me</button>
    <script>
      function fun() {
        var stud = prompt("Exams are near,have you started preparing for ?");
        
        if (stud == "No" || stud == "no" || stud == "NO") {
          alert("Start Preparing");
          confirm("Preparing for study");
        }
        if (stud == "Yes" || stud == "yes" || stud == "YES") {
          alert("Good");
          confirm("Finish your study");
        }
      }
    </script>
  </body>
</html>

 
2) Add or append in paragraph text and also in the numbered(ordered) list in a given HTML document using jQuery selectors.
[Hint : Use Append( ) method]

Solution:-

 <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>JQuery</title>
    <!-- Internet is required for the jquery effect -->
    <script
      src="https://code.jquery.com/jquery-3.6.0.js"
      integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
      crossorigin="anonymous"
    ></script>
  </head>

  <body>
    <script>
      $(document).ready(function () {
        $("#btn1").click(function () {
          $("p").append("<h2>Hello World</h2>");
        });

        $("#btn2").click(function () {
          $("ol").append("<li>Java</li>");
        });
      });
    </script>
    <p>After This Paragraph Some Text Will Be Added...</p>
    <ol>
      <li>Php</li>
      <li>Python</li>
      <li>C</li>
      <li>Ruby</li>
    </ol>
    <button id="btn1">Appended Text</button>
    <button id="btn2">Appended List</button>
  </body>
</html>

 SET B:
1) Write a javascript function to validate username and password for a membership form.

Solution:-

 <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <center>
      Enter Username : <input type="text" name="user" id="u" /><br />
      Enter Password : <input type="password" name="pass" id="p" /><br />
      <input type="button" value="submit" onclick="check()" />
    </center>

    <script>
      function check() {
        var i;
        flag = false;
        var us = document.getElementById("u").value;
        var ps = document.getElementById("p").value;
        if (
          us.length >= 6 &&
          us.length <= 15 &&
          ps.length >= 6 &&
          ps.length <= 15
        ) {
          for (var i = 0; i < (us.length || ps.length); i++) {
            if (
              (us.charAt(i) >= "a" && us.charAt(i) <= "z") ||
              (us.charAt(i) >= "A" && us.charAt(i) <= "Z") ||
              (us.charAt(i) >= "0" && us.charAt(i) <= "9")
            ) {
              if (
                (ps.charAt(i) >= "a" && ps.charAt(i) <= "z") ||
                (ps.charAt(i) >= "A" && ps.charAt(i) <= "Z") ||
                (ps.charAt(i) >= "0" && ps.charAt(i) <= "9") ||
                ps.charAt == "@" ||
                ps.charAt == "#" ||
                ps.charAt == "$"
              ) {
                flag = true;
              } else flag = false;
            }
          }
          if (flag == true) {
            alert("Login Succesfully");
          } else {
            alert("Invalid Username and Password");
          }
        } else alert("Invalid due to Length");
      }
    </script>
  </body>
</html>


2) To insert text before and after an image using jQuery.
[Hint : Use before( ) and after( )]

Solution:-

 <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- Internet is required for the jquery effect -->
    <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
</head>

<hr>
    <script>
        $(document).ready(function () {
            $("#ib").click(function () {
                $("h1").before('<img src = "Pune.jpg" alt = "Img not found" height = "200px">')
            });
            $("#ia").click(function () {
                $("h1").after('<img src = "Pune.jpg" alt = "Img not found" height = "200px">')
            });
        });
    </script>

    <h1>Show Image</h1>
    <hr>
<button type="button" id="ib"> Insert Before </button>
<button type="button" id="ia"> Insert After </button>    
<hr>

</body>

</html>


SET C:
1) Write a Javascript program to accept name of student, change font color to red, font size to 18 if student name is present otherwise on clicking on empty text box display image which changes its size (Use onblur, onload, onmousehover, onmouseclick, onmouseup)

Solution:-

 <html>
  <head>
    <script type="text/javascript"></script>
    <script>
      function change() {
        var cnt = 0;
        var name1 = document.getElementById("n").value;

        if (name1 != "") {
          document.getElementById("n").style.color = "blue";
          document.getElementById("n").style.fontSize = "18px";
        } else {
          var img = new Image();

          var div = document.getElementById("d");

          img.onload = function imag() {
            div.appendChild(img);
          };
          img.src = "Pune.jpg";
        }
      }
    </script>
  </head>

  <body>
    <h4>OnClick</h4>
    <br />
    Enter Name <input type="text" name="name" id="n" onclick="change()" />

    <!--     
<h4>OnBlur</h4><br>
Enter Name <input type = "text" name = "name" id = "n" onblur="change()"><br> -->

    <!-- <h4>OnMouseOver</h4><br>
Enter Name <input type = "text" name = "name" id = "n" onmouseover="change()"> -->

    <!-- <h4>OnMouseUp</h4>
    <br />
    Enter Name <input type="text" name="name" id="n" onmouseup="change()" /> -->

    <!--
Enter Name <input type = "text" name = "name" id = "n" onload="change()">
-->

    <div id="d"></div>
  </body>
</html>

 2) Remove div section elements after clicking on button using jQuery.
[Hint : Use #id selector] 

Solution:-

<html>
  <head>
    <!-- Internet is required for the jquery effect -->
    <script
      src="https://code.jquery.com/jquery-3.6.0.js"
      integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
      crossorigin="anonymous"
    ></script>
    <script>
      $(document).ready(function () {
        $("#btn1").click(function () {
          $("div").remove();
        });
      });
    </script>
  </head>

  <body>
    <h1>Demo : JQuery Remove() Method</h1>
    <div>
      <h1>Demo : JQueryremove() Method</h1>
    </div>

    <button id="btn1">Remove</button>
  </body>
</html>


WT-II Assignment-2

 Assignment No 2. XML documents and DOM

 Set A :
1) Write a script to create XML file named “Item.xml”
<Item>
<ItemName> ................ </ItemName>
<ItemPrice> ...................</ItemPrice>
<Quantity> ..................... </Quantity>
</Item>
Store the details of 5 Items of different Types

Solution:-

<?xml version="1.0" encoding ="UTF-8"?>
<Item>

<item type="fruit">
<ItemName>Mango</ItemName>
<ItemPrice>12</ItemPrice>
<Quantity>12</Quantity>
</item>

<item type="Vegetables">
<ItemName>Potato</ItemName>
<ItemPrice>10</ItemPrice>
<Quantity>12</Quantity>
</item>

<item type="Cerial">
<ItemName>Moong</ItemName>
<ItemPrice>120</ItemPrice>
<Quantity>2</Quantity>
</item>

<item type="Grocerry">
<ItemName>Sugar</ItemName>
<ItemPrice>40</ItemPrice>
<Quantity>2</Quantity>
</item>

<item type="Stationary">
<ItemName>Pen</ItemName>
<ItemPrice>4</ItemPrice>
<Quantity>12</Quantity>
</item>
</Item>
 

2) Link “ Item. Xml” file to the CSS style sheet and get well formatted output as given below
i)ItemName :
Color : red;
Font-family : copperplate Gothic Light;
Font-size : 16pt;
Font :bold;

ii)ItemPrice and Quantity
color:yellow;
font-family:Arial;
font-size:12 pt;
font:bold;

 

Solution:-

A2.css

  ItemName
{
    color:red;
    font-family:copperplate Gothoic Light;
    font-size:16pt;
    font:bold;
}
ItemPrice,Quantity
{
    color:yellow;
    font-family:Arial;
    font-size:12pt;
    font:bold;
}


A2.xml

<?xml version="1.0" encoding ="UTF-8"?>
<?xml-stylesheet type = "text/css" href = "A2.css"?>
<Item>
<item type="fruit">
<ItemName>Mango</ItemName>
<ItemPrice>12</ItemPrice>
<Quantity>12</Quantity>
</item>

<item type="Vegetables">
<ItemName>Potato</ItemName>
<ItemPrice>10</ItemPrice>
<Quantity>12</Quantity>
</item>

<item type="Cerial">
<ItemName>Moong</ItemName>
<ItemPrice>120</ItemPrice>
<Quantity>2</Quantity>
</item>

<item type="Grocerry">
<ItemName>Sugar</ItemName>
<ItemPrice>40</ItemPrice>
<Quantity>2</Quantity>
</item>

<item type="Stationary">
<ItemName>Pen</ItemName>
<ItemPrice>4</ItemPrice>
<Quantity>12</Quantity>
</item>
</Item>

 

3) Write a PHP script to generate an XML file in the following format in PHP.
<?xml version="1.0" encoding="UTF-8"?>
<BookInfo>
<book>
<bookno>1</bookno>
<bookname>JAVA</bookname>
<authorname> Balguru Swami</authorname>
<price>250</price>
<year>2006</year>
</book>
<book>
<bookno>2</bookno>
22<bookname>C</bookname>
<authorname> Denis Ritchie</authorname>
<price>500</price>
<year>1971</year>
</book>
</BookInfo>


Solution:-

<!-- You have to just write this program xml file will be automatically created after running this php code.. -->

<?php
$bookInfo = new SimpleXMLElement("<BookInfo/>");
$book=$bookInfo ->addChild("book");
$book->addChild("bookno","1");
$book->addChild("bookname","java");
$book->addChild("authorname","Balguru Swami");
$book->addChild("price","250");
$book->addChild("year","2006");

$book=$bookInfo ->addChild("book");
$book->addChild("bookno","2");
$book->addChild("bookname","C");
$book->addChild("authorname","Denis Ritchie");
$book->addChild("price","500");
$book->addChild("year","1971");

$bookInfo -> asXML("Book.xml");
?>

 Set B
1. Write PHP script to read above created “book.xml” file into simpleXML object. Display attributes and elements .(Hint  simple_xml_load_file() function )

Solution:-

Php file -
<?php
$xml=simplexml_load_file("Book.xml") or die("eror:cannot create object");
var_dump($xml);
?>


2. Write a PHP script to read “Movie.xml” file and print all MovieTitle and ActorName of file using DOM Document Parser. “Movie.xml” file should contain following information with at least 5 records with values.

MovieInfo
MovieNo, MovieTitle, ActorName , ReleaseYear


Solution:-

Movie.xml

<?xml version="1.0" encoding="UTF-8"?>
<MovieInfo>
    <Movie>
        <MovieNo>
            1
        </MovieNo>
        <MovieTitle>
            WAR
        </MovieTitle>
        <ActorName>
            Hritik Roshan
        </ActorName>
        <ReleaseYear>
            2020
        </ReleaseYear>
    </Movie>
    <Movie>
        <MovieNo>
            2
        </MovieNo>
        <MovieTitle>
            DDLJ
        </MovieTitle>
        <ActorName>
            Shahrukh Khan
        </ActorName>
        <ReleaseYear>
            1994
        </ReleaseYear>
    </Movie>
    <Movie>
        <MovieNo>
            3
        </MovieNo>
        <MovieTitle>
            KGF
        </MovieTitle>
        <ActorName>
            Yash
        </ActorName>
        <ReleaseYear>
            2022
        </ReleaseYear>
    </Movie>
    <Movie>
        <MovieNo>
            4
        </MovieNo>
        <MovieTitle>
            RRR
        </MovieTitle>
        <ActorName>
            Ram
        </ActorName>
        <ReleaseYear>
            2022
        </ReleaseYear>
    </Movie>
    <Movie>
        <MovieNo>
            5
        </MovieNo>
        <MovieTitle>
            PUSHPA
        </MovieTitle>
        <ActorName>
            Allu Arjun
        </ActorName>
        <ReleaseYear>
            2022
        </ReleaseYear>
    </Movie>
</MovieInfo>


Movie.php

<?php

$xml = simplexml_load_file('Movie.xml');

echo '<h2>Movie Title and Actor Name</h2>';

$list = $xml->Movie;

for ($i = 0; $i < count($list); $i++) {

    echo 'Movie Name: ' . $list[$i]->MovieTitle . '<br>';

    echo 'Actor Name: ' . $list[$i]->ActorName . '<br><br>';

}


 Set C
1. Create a XML file which gives details of movies available in “Movie CD Store “ from following categories
a) Classical
b) Horror
c) Action
Elements in each category are in the following format
<Category>
<MovieTitle> ................ </ MovieTitle >
<ActorName> ...................</ActorName>
<ReleaseYear> ..................... </ReleaseYear>
</Category>
Save the file with name “movies.xml”

 Solution:-

 catalogue.xml

<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="catlogue.css"?>
<CATALOG>
<CD code="B1">
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD code="B2">
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
</CATALOG>


Catalogue.php
<html>
<head>
<link rel="stylesheet" type="text/css" href="catlogue.css">
</head>
<body>
<?php
$xml=simplexml_load_file('catlogue.xml')or die("cannot die");
?>
<center>
</b>CD details</b></center>
<table border="1">
<th>CD code</th>
<th>Title</th>
<th>ARTIST</th>
<th>COUNTRY</th>
<th>COMPANY</th>
<th>PRICE</th>
<th>Year</th>
<?php
foreach($xml->CD as $a)
{
echo"<tr><td>".$a['code']."</td>";
echo"<td>".$a->TITLE."</td>";
echo"<td>".$a->ARTIST."</td>";
echo"<td>".$a->COUNTRY."</td>";
echo"<td>".$a->COMPANY."</td>";
echo"<td>".$a->PRICE."</td>";
echo"<td>".$a->YEAR."</td>
</tr>";
}
?>
</table>
</body>
</html>


catlogue.css
table th{color:blue; font-size: 20pt;}
table td{color:green; font-size: 20pt;}

WT-II Assignment-1

 Assignment No 1. Cookies and Session

Set A
1. Write a PHP script to keep track of number of times the web page has been access. [Use session and cookies]


Solution:- 

<?php
//session start
session_start();
if(isset($_SESSION['count']))
{
$_SESSION['count'] = $_SESSION['count'] +1;
}
else
{
$_SESSION['count'] =1;
}
echo " No of times the web page has been access ".$_SESSION['count'];
?>

 

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

Solution:-

 Ass1_2.html

<html>

<body>
    <table border="1" align=center>
        <form action="http://localhost/PHP/Practical/Web-Development/Assignment1/second.php">
            <tr>
                <td>
                    <b>Select font style
                </td>
                <td>
                    <input type="text" name="s1"><br>
                </td>
            </tr>

            <tr>
                <td>
                    <b>Enter font size
                </td>
                <td>
                    <input type="text" name="s"><br>
                </td>
            </tr>

            <tr>
                <td>
                    <b>Enter font colour
                </td>
                <td>
                    <input type="text" name="c"><br>
                </td>
            </tr>

            <tr>
                <td>

                    <b>Enter Background Colour
                </td>
                <td>
                    <input type="text" name="b"><br>
                </td>
            </tr>

            <tr>
                <td>
                    <input type="submit" value="next">
                </td>
            </tr>

        </form>
    </table>
</body>

</html>

Second.php

<?php
ob_start();
echo "Style is : ".$_GET['s1']."<br>";
echo "Size is : ".$_GET['s']."<br>";
echo "Color is : ".$_GET['c']."<br>";
echo "Background color is : ".$_GET['b']."<br>";
setcookie("set1",$_GET['s1']);
setcookie("set2",$_GET['s']);
setcookie("set3",$_GET['c']);
setcookie("set4",$_GET['b']);
?>

<html>
<body>
<form action = "http://localhost/PHP/Practical/Web-Development/Assignment1/third.php">
<input type="submit" value="OK" value="submit">
</form>
</body>
</html>

third.php

<?php
$fstyle =$_COOKIE['set1'];
$fsize=$_COOKIE['set2'];
$fcolor=$_COOKIE['set3'];
$background=$_COOKIE['set4'];

$name = "Shubham";
echo "<body bgcolor =$background >";
echo "<font color=$fcolor size=$fsize style=$fstyle > $name";
?>


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]

Solution:- 

B1.html

<html>
<body>
<form action = "http://localhost/PHP/Practical/Web-Development/Assignment1/B1.php">
    <table class="center"    style = "background-color:powderblue"  >
        <tr>
        <td>
        Enter User Name :
        </td>
        <td>
        <input type="text" name="user"   required>
        </td>
        </tr>

        <tr>
        <td>
        Enter Password:
        </td>
        <td>
        <input type="password" name="pass" required>
        </td>
        </tr>

        <tr>
        <td>
        <input type="submit" name="submit" value="submit" class="btn orange" >
        </td>
        </tr>
    </table>
    </form>
    </body>

</html>


B1.php

<?php
//session start

session_start();
$u=$_GET['user'];
$p=$_GET['pass'];

if(isset($_SESSION['count']))
{
    $_SESSION['count'] = $_SESSION['count'] +1;   
}

else
    {
        $_SESSION['count'] =1;
    }


if($_SESSION['count']<=3 && $u="shubham" && $p="great")
        {
             echo "Welcome Man";
        }
    else
        {
            echo "Errors";
        }
?>


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]

Solution:- 

 B2Emp.html

<html>
  <body>
    <style>
      table,
      tr,
      td {
        border: 1px solid black;
        border-collapse: collapse;
      }
      tr,
      td {
        padding: 10px;
      }
      table.center {
        margin-left: auto;
        margin-right: auto;
      }
      .btn {
        border: 2px solid black;
        background-color: white;
        color: black;
        padding: 8px 16px;
        font-size: 16px;
        cursor: pointer;
        border-radius: 5px;
      }
      .success:hover {
        background-color: #04aa6d;
        color: white;
      }
      .orange:hover {
        background: #f44336;
        color: white;
      }
    </style>
    <form
      action="http://localhost/PHP/Practical/Web-Development/Assignment1/B2Emp.php"
    >
      <table class="center" style="background-color: powderblue">
        <tr>
          <td>Enter Employee No :</td>
          <td>
            <input type="text" name="num" required />
          </td>
        </tr>

        <tr>
          <td>Enter Employee Name :</td>
          <td>
            <input type="text" name="name" required />
          </td>
        </tr>

        <tr>
          <td>Enter Employee Address :</td>
          <td>
            <input type="text" name="add" required />
          </td>
        </tr>

        <tr>
          <td>
            <input type="submit" name="submit" value="submit" class="btn orange" />
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>


B2Emp.php

<?php
session_start();
$_SESSION['ename']=$_GET['name'];
$_SESSION['eno']=$_GET['num'];
$_SESSION['eadd']=$_GET['add'];
?>

<html>
<body >       
        <style>
        table,tr,td{
        border :1px solid black ;
        border-collapse : collapse;
        }
        tr,td{
        padding : 10px;
        }
        table.center{
        margin-left:auto;
        margin-right:auto;
        }
        .btn{
        border :2px solid black ;
        background-color:white;
        color:black;
        padding: 8px 16px;
        font-size:16px;
        cursor:pointer;
        border-radius:5px;
        }
        .success:hover{
        background-color:#04AA6D;
        color:white;
        }
        .orange:hover{
        background:#f44336;
        color:white;
        }
        </style>
<form action = "http://localhost/PHP/Practical/Web-Development/Assignment1/B2.php">
    <table class="center"    style = "background-color:powderblue"  >
<caption>Basic Salary</caption>
    <tr>
        <td>
        Enter Basic Salary:
        </td>
        <td>
        <input type="text" name="bs"   required>
        </td>
        </tr>

        <tr>
        <td>
        Enter DA :
        </td>
        <td>
        <input type="text" name="da"   required>
        </td>
        </tr>

        <tr>
        <td>
        Enter HRA :
        </td>
        <td>
        <input type="text" name="hda"   required>
        </td>
        </tr>

        <tr>
        <td>
        <input type=submit name="submit" value="submit" class="btn orange" >
        </td>
        </tr>
    </table>
    </form>
    </body>

</html>


B2.php

<?php
session_start();
$_SESSION['ebasic']=$_GET['bs'];
$_SESSION['empda']=$_GET['da'];
$_SESSION['empdha']=$_GET['hda'];

$number = $_SESSION['eno'];
$name = $_SESSION['ename'];
$address = $_SESSION['eadd'];
$basic = $_SESSION['ebasic'];
$da = $_SESSION['empda'];
$hda = $_SESSION['empdha'];

echo "Employee Details"."<br>";

echo "Employee Number : ".$number."<br>";
echo "Employee Name : ".$name."<br>";
echo "Employee Address : ".$address."<br>";
echo "Employee Basic Salary : ".$basic."<br>";
echo "Employee DA Salary : ".$da."<br>";
echo "Employee HDA Salary : ".$hda."<br>";

$total = $basic+$da+$hda;

echo "Total Salary is : ".$total."<br>";
?>


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. 

Solution:- 

C1Cust.html

<html>
  <body>
    <style>
      table,
      tr,
      td {
        border: 1px solid black;
        border-collapse: collapse;
      }
      tr,
      td {
        padding: 10px;
      }
      table.center {
        margin-left: auto;
        margin-right: auto;
      }
      .btn {
        border: 2px solid black;
        background-color: white;
        color: black;
        padding: 8px 16px;
        font-size: 16px;
        cursor: pointer;
        border-radius: 5px;
      }
      .success:hover {
        background-color: #04aa6d;
        color: white;
      }
      .orange:hover {
        background: #f44336;
        color: white;
      }
    </style>
    <form action="http://localhost/PHP/Practical/Web-Development/Assignment1/C1Cust.php">
      <table class="center" style="background-color: powderblue">
        <tr>
          <td>Enter Customer Name :</td>
          <td>
            <input type="text" name="name" required />
          </td>
        </tr>

        <tr>
          <td>Enter Customer Address :</td>
          <td>
            <input type="text" name="add" required />
          </td>
        </tr>

        <tr>
          <td>Enter Mobile Number:</td>
          <td>
            <input type="text" name="num" required />
          </td>
        </tr>

        <tr>
          <td>
            <input type="submit" name="submit" value="submit" class="btn orange" />
          </td>
        </tr>
        
      </table>
    </form>
  </body>
</html>

C1Cust.php

<?php
session_start();
$_SESSION['cname']=$_GET['name'];
$_SESSION['cadd']=$_GET['add'];
$_SESSION['cno']=$_GET['num'];
?>

<html>
<body >       
        <style>
        table,tr,td{
        border :1px solid black ;
        border-collapse : collapse;
        }
        tr,td{
        padding : 10px;
        }
        table.center{
        margin-left:auto;
        margin-right:auto;
        }
        .btn{
        border :2px solid black ;
        background-color:white;
        color:black;
        padding: 8px 16px;
        font-size:16px;
        cursor:pointer;
        border-radius:5px;
        }
        .success:hover{
        background-color:#04AA6D;
        color:white;
        }
        .orange:hover{
        background:#f44336;
        color:white;
        }
        </style>
<form action = "http://localhost/PHP/Practical/Web-Development/Assignment1/C1.php">
    <table class="center"    style = "background-color:powderblue"  >
<caption>Product Information</caption>
    <tr>
        <td>
        Enter Product Name:
        </td>
        <td>
        <input type="text" name="pname"   required>
        </td>
        </tr>

        <tr>
        <td>
        Enter Quantity:
        </td>
        <td>
        <input type="text" name="q"   required>
        </td>
        </tr>

        <tr>
        <td>
        Enter Rate :
        </td>
        <td>
        <input type="text" name="rate"   required>
        </td>
        </tr>

        <tr>
        <td>
        </td>
        <td>
        <input type=submit name="submit" value="submit" class="btn orange" >
        </td>
        </tr>
    </table>
    </form>
    </body>

</html>


C1.php

<?php
session_start();
$_SESSION['pname']=$_GET['pname'];
$_SESSION['pqty']=$_GET['q'];
$_SESSION['prate']=$_GET['rate'];

$name = $_SESSION['cname'];
$address = $_SESSION['cadd'];
$number = $_SESSION['cno'];
$product =$_SESSION['pname'];
$quantity = $_SESSION['pqty'];
$rate =$_SESSION['prate'];

echo "Bill Details"."<br>";

echo "Customer Name : ".$name."<br>";
echo "Customer Address : ".$address."<br>";
echo "Customer Number : ".$number."<br>";
echo "Product Name : ".$product."<br>";
echo "Product Quantity : ".$quantity."<br>";
echo "Product Rate : ".$rate."<br>";

$total = $quantity*$rate;

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


WT-I Assignment-5

 Assignment : 5 To study Files and Database (PHP-PostgreSQL)

 

SetA
Q1.Write a program to read one file and display the contents of the file with its size.

Solution :

<?php

$filenm=$_GET['t1'];

$fp=fopen($filenm,'r');

$fs=filesize($filenm);

echo fread($fp,$fs);

echo "filesize is".$fs;

?>

<!DOCTYPE html>

<html>

<head><title>Assign 5 set a q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass5a2.php>

Enter file name: <input type=text name=t1>

<input type=submit value=Submit>

</form>

</body>

</html>

 

Q2. Consider the following entities and their relationships
Event (eno , title , date )
Committee ( cno , name, head , from_time ,to_time , status)
Event and Committee have many to many relationship. Write a script to accept title of event modify status committee as working.

Solution :-

<!DOCTYPE html>

<html>

<head><title>Assign 6 set a q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass6a1.php>

Enter title: <input type=text name=t1>

<input type=submit value=Update>

</form>

</body>

</html>

<?php

$c=pg_connect("host=192.168.100.252 dbname=tydb3 user=ty3")

if(!$c)

echo 'not connected';

else

echo "done \n";

$e=$_GET['t1'];

$q=pg_query("update comm set status ='not done' where cno in (select cno from e_c where eno

in (select eno from event where title='0'));");

if(!$q)

echo "not updated";

else

echo "\n updated!";

?>



SetB
Q1) Write a program to read a flat file “item.dat”, which contains details of 5 different items such  as Item code, Item Name, unit sold, and Rate. Display the Bill in tabular format.

Solution:-

Item.dat

1 Book 10 15

2 Pen 5 10

3 Pencil 8 5

4 Bag 10 200

5 File 4 25

<!DOCTYPE html>

<html>

<body>

<?php

$filenm="item.dat";

$fp=fopen($filenm,'r');

?>

<centre>

<table border=2>

<?php

echo"<br><tr><th> item no</th><th> item name</th><th>unit sold</th><th>rate</th><th>total amt</th></tr></br>";

while(!feof($fp))

{

$x=explode(" ",fgets($fp));

$t=$x[2]*$x[3];

echo "<tr><td>$x[0]</td><td>$x[1]</td><td>$x[2]</td><td>$x[3]</td><td>$t</td></tr>";

}

?>

</table>

</centre>

</body>

</html>

 


Q2) Consider the following entities and their relationships
Student (Stud_id,name,class)
Competition (c_no,c_name,type)
Relationship between student and competition is many-many with attribute rank and year. Create a RDB in 3NF for the above and solve the following. Using above database write a script in PHP to accept a competition name from user and display information of student who has secured 1st rank in that competition.

Solution:-


 

SetC
Q 1. Write a menu driven program to perform various file operations. Accept filename from user.
a) Display type of file.
b) Display last access time of file
c) Display the size of file
d) Delete the file

Solution:-

<!DOCTYPE html>

<html>

<head><title>Assign 5 set b q1</title></head>

<body>

<table border=1>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass5b1.php>

<tr><td>Enter file name: </td><td><input type=text name=t1></td></tr>

<tr><td><input type=radio name=r value=1></td><td>Display type of file</td></tr>

<tr><td><input type=radio name=r value=2></td><td>Display last access time of file</td></tr>

<tr><td><input type=radio name=r value=3></td><td>Display size of file</td></tr>

<tr><td><input type=radio name=r value=4></td><td>Delete the file</td></tr>

<tr><td colspan=2><input type=submit value=Submit></td></tr>

</form>

</table>

</body>

</html>

<?php

$f=$_GET['t1'];

$fp=fopen($f,"r");

$ch=$_GET['r'];//option name r

switch($ch)

{

case 1:

echo "Type of file: ".filetype($f);

break;

case 2:

echo "Last access time: ".date("F d Y H:i:s.",fileatime($f)); //day date year hr min seconds

break;

case 3:

echo "File size: ".filesize($f);

break;

case 4:

unlink($f);

if(!unlink($f))

{

echo "<br>Error deleting file";

}

else

{

echo "File deleted";

}

break;

}

?>


 

Q 2. Property (pno, description, area)
a. Owner (oname, address, phone)
b. An owner can have one or more properties, but a property belongs to exactly one owner. 

c. Accept owner name from the user. Write a PHP script which will display all properties which are own by that owner 

Solution:-


<!DOCTYPE html>

<html>

<head><title>Assign 6 set b q1</title></head>

<body>

<form name=f1 method=get action=http://192.168.100.252/ty2/ass6b1.php>

Enter name: <input type=text name=t1>

<input type=submit value=Show>

</form>

</body>

</html>

<?php

$c=pg_connect("host=192.168.100.252 dbname=tydb2 user=ty2");

if(!$c)

echo "not connected";

else

echo "done";

$t=$_GET['t1'];

$q=pg_query("select * from property where oname='".$t."';");

while($rs=pg_fetch_array($q))

{

echo "<br>Name: ".$rs[3]."<br>Property: ".$rs[1];

echo "<br>-----------";

}

?>



WT-I Assignment -4

 ASSIGNMENT NO. 4 : TO STUDY ARRAYS

Set A
1. Create your array of 30 high temperatures, approximating the weather for a spring month, then find the average high temp, the five warmest high temps and the five coolest high temps. Display the result on the browser.
Hint: a) Use array_slice b) the HTML character entity for the degree sign is & deg;.

Solution:-

<html>
    <head>
        <title>High temparature Array</title>
    </head>
    <h2>High temperature for spring month </h2>
    <?php
        $highTemps = array(68,70,72,58,60,79,82,73,75,77,73,58,63,79,78,68,72,73,80,79,68,72,75,77,73,78,82,85,89,83);

        $count=count($highTemps);

        $total=0;
        foreach($highTemps as $h)
        {
            $total+=$h;
        }
        $avg = round($total/$count);
        echo"<p> the average high temp for the month was $avg  &deg; f.<p>\n";
        rsort($highTemps);
        $topTemps = array_slice($highTemps,0,5);
        echo"<p>the warmest fire high temperature were;<br>\n";
        foreach($topTemps as $t)
        {
            echo "$t &deg;F<br>\n";
        } 
        echo"<p>";
        $lowTemps = array_slice($highTemps,-5,5);
        echo "<p> the coolest fire high temp.were:<br>\n";
        foreach($lowTemps as $l)
        {
            echo "$l &deg;F<br> \n";
        }
        echo"<p>";  
    ?>
    </html>


 

2. Write a menu driven program to perform the following stack and queue related  operations:[Hint: use Array_push(), Array_pop(), Array_shift(), Array_unshift() ]
a) Insert an element in stack
b) Delete an element from stack
c) Display the contents of stack
d) Insert an element in queue
e) Delete an element from queue
f) Display the contents of queue

Solution:-

html file!!!

<!DOCTYPE html>

<html>

<body>

<form name=f method=get action=http://192.168.100.252/sy31/a4sa2.php>

<center>

<table>

<tr><th colspan=2><h1>Choose Menu</h1></th></tr>

<tr><td>Ente an array:</td> <td><input type=text name =a1></td></tr><br>

<tr><td>Enter an element to be inserted:</td> <td><input type=text name =w></td></tr><br>

<tr><td><input type=radio name=op value=1></td> <td>a.Insert an element in stack.</td></tr><br>

<tr><td><input type=radio name=op value=2></td> <td>b.Delete an element from stack.</td></tr><br>

<tr><td><input type=radio name=op value=3></td> <td>c.Display the contents of stack.</td></tr><br>

<tr><td><input type=radio name=op value=4></td> <td>d.Insert an element in queue.</td></tr><br>

<tr><td><input type=radio name=op value=5></td> <td>d.Delete an element from queue.</td></tr><br>

<tr><td><input type=radio name=op value=6></td> <td>d.Display the contents of queue.</td></tr><br>

<tr><th colspan=2><input type=submit name=sb value=Submit></th></tr>

</table>

</center>

</body>

</html>

/*as4seta2.php*/

<?php

$w=explode(",",$_GET['a1']); //1,2,3,7,10

$a=$_GET['op'];

/*$b=array(1,2,3,4,5,6,7,8,9);*/

switch($a)

{

case 1:

print_r($w);

array_push($w,10);

echo"<br>";

echo"After insert an element in stack:<br>";

print_r($w);break;

case 2:

print_r($w);



array_pop($w);

echo"<br>";

echo"After delete an element from stack :<br>";

print_r($w);break;

case 3:

echo "Contents of stack.<br>";

print_r($w);break;

case 4:

print_r($w);

array_unshift($w,9);

echo"<br>";

echo"After insert an element in queue:<br>";

print_r($w);break;

case 5:

print_r($w);

array_shift($w);

echo"<br>";

echo"After delete an element in queue:<br>";

print_r($w);break;

case 6:

echo "Contents of queue<br>";

print_r($w);break;

}

?>


 

Set B
1. Write a PHP script that inserts a new item in an array at any position.
(hint : use array_splice())

Solution :-

<?php
    $given=array('1','2','3','4','5');
    echo "Given Array: <br>";
    foreach($given as $x)
    {
        echo "$x";
    }
    $inserted ='@';
    array_splice($given,3,0,$inserted);
    echo "<br> After inserting '@' the array is :"."\n";
    foreach($given as $x)
    {
        echo "$x";
    }
    echo "\n";
?>

<!--
 O/P:
Given Array:
12345
After inserting '@' the array is : 123@45
-->


2. Define an array. Find the elements from the array that matches the given value using appropriate search function.
 Solution:-

<!DOCTYPE html>

<html>

<body>

<form name=f method=get action=http://localhost/as4setb2.php>

<center>

<table>

<tr><th colspan=2><h1>Choose Menu</h1></th></tr>

<tr><td>Ente an array:</td> <td><input type=text name =w></td></tr><br>

<tr><th colspan=2><input type=submit name=sb value=Submit></th></tr>

</table>

</center>

</body>

</html>

/*as4setb2.php*/

<?php

$a=array('inaara rajwani',' bcs', 'ty');

print_r($a);

$w1=$_GET ['w'];

print_r($w1);

if(in_array($w1,$a))

{

echo "The given element is found in defined array ";

}

else

{

echo "The given element is not found in defined array ";

}

?>

Set C
1. Write a PHP script to sort the following associative array :
array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40") in
a) ascending order sort by value
b) ascending order sort by Key
c) descending order sorting by Value
d) descending order sorting by Key


Solution:-

/*as4setc1*/

<?php

$array=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");

echo "Associative array : Ascending order sort by value <br>";

asort($array);

foreach($array as $y=>$y_value)

{

echo "Age of ".$y." is : ".$y_value."<br>";

}

echo "Associative array : Ascending order sort by Key <br>";

ksort($array);

foreach($array as $y=>$y_value)

{

echo "Age of ".$y." is : ".$y_value."<br>";

}

echo "Associative array : Descending order sorting by Value<br>";

arsort($array);

foreach($array as $y=>$y_value)

{

echo "Age of ".$y." is : ".$y_value."<br>";

}

echo "Associative array : Descending order sorting by Key<br>";

krsort($array);

foreach($array as $y=>$y_value)

{

echo "Age of ".$y." is : ".$y_value."<br>";

}

?>

2. Write a menu driven program to perform the following operations on associative arrays:
a) Split an array into chunks
b) Sort the array by values without changing the keys.
c) Filter the odd elements from an array.
d) Merge the given arrays.
e) Find the intersection of two arrays.
f) Find the union of two arrays.
g) Find set difference of two arrays. 

Solution:-

<html>

<title>Assign4_SETC_Q2</title>

<body>

<center>

<table>

<form name=f method=get action="http://localhost/as4setc2.php">

<tr><th colspan=2>Menu</th></tr>

<tr><td>1.Split array into chunks</td><td><input type=radio name=r value=1></td></tr>

<tr><td>2.Sort array by value without changing key</td><td><input type=radio name=r value=2></td></tr>

<tr><td>3.Filter odd elements</td><td><input type=radio name=r value=3></td></tr>

<tr><td>4.Merge given array</td><td><input type=radio name=r value=4></td></tr>

<tr><td>5.Find intersection</td><td><input type=radio name=r value=5></td></tr>

<tr><td>6.Find union</td><td><input type=radio name=r value=6></td></tr>

<tr><td>7.Find set difference</td><td><input type=radio name=r value=7></td></tr>

<tr><td>SUBMIT</td><td><input type=submit name=s value=go></td></tr>

<center>

</form>

</table>

</body>

</html>

/*as4setc2.php*/

<?php

$c=$_GET['r'];

$a=array('pen'=>15,'pencil'=>5,'rubber'=>3,'book'=>30);

$a1=array('ira'=>15,'nia'=>57,'ria'=>3,'alia'=>30);

//$a2=array(15,48,10,155,2,78);

switch($c)

{

case 1:

echo"<br>Array in chunks of two <br>";

print_r(array_chunk($a,2,true));

echo"<br><br>";

print_r(array_chunk($a1,2,true));

echo"<br><br>";

break;

case 2:

print_r($a);

asort($a);//array sort by values

echo"<br>Array in ascending order<br>";

print_r($a);

arsort($a);//reverse array sort by values

echo"<br>Array in desecending order<br>";

print_r($a);

break;

case 3:

function isodd($v)

{

return $v%2;

}

print_r($a);

echo "<br>";

echo"<br>Filter the odd elements from an array.<br>";

print_r(array_filter($a,'isodd'));

break;

case 4 :

echo "<br>1st array<br>";

print_r($a);

echo "<br>2nd array<br>";

print_r($a1);

echo "<br>Array Merge<br>";

print_r(array_merge($a,$a1));

break;

case 5:

echo "<br>1st array<br>";

print_r($a);

echo "<br>2nd array<br>";

print_r($a1);

echo "<br>Array Intersection<br>";

print_r(array_intersect($a,$a1));

break;

case 6:

echo "<br>1st array<br>";

print_r($a);

echo "<br>2nd array<br>";

print_r($a1);

echo "<br>Array Union<br>";

$union=array_merge($a,$a1);

print_r(array_unique($union));

break;

case 7:

echo "<br>1st array<br>";

print_r($a);

echo "<br>2nd array<br>";

print_r($a1);

echo "<br>Array Differnce<br>";

print_r(array_diff($a,$a1));

break;

}