Friday, January 31, 2025

WT-II Assignment 5

 ASSIGNMENT 5: PHP Framework CODEIGNITER

Set A 

1. Create a CSS file to apply the following styling for an HTML document.  

Background color: blue, 

H1 

Color : red, 

Font-family : Verdana, 

Font-size : 8 

Color : green, 

Font-family : Monospace, 

Font-size :10 



2. Add a Javascript file in codeigniter. The javascript code should check whether a 

number is positive or negative.  




Set B 

1. Create a table student having attributes (rollno, name, class). Assume appropriate data types for the attributes. Using Codeigniter , connect to the database and insert minimum 5 records in it. 



2. For the above table student, display all its records using Codeigniter. 



Set C 

1. Create a form to accept personal details of customer (name, age, address). Once the personal information is accepted, on the next page accept order details such as (product name, quantity). Display the personal details and order details on the third page. (Use cookies) 




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)



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:-

 HTML file :

<html>

<head>

<style>

span

{

                font-size: 25px;

}

table

{

                color: blueviolet; ;

}

</style>


<script type="text/javascript" >

                function print()

                {

                                var ob=false;

                                ob=new XMLHttpRequest();

             

                                ob.open("GET","slip14_Q2.php?");//emailid="+eid);

                                ob.send();         

             

                                ob.onreadystatechange=function()

                                {

                                                if(ob.readyState==4 && ob.status==200)

                                                {

                                                                document.getElementById("i").innerHTML=ob.responseText;

                                                }

                                }

                }           

</script>

</head>


<body>

<center>

<h3>Display the contents of a contact.dat file </h3>

<br><input  type="button"  value=Print onclick="print()" >

<span id="i"></span>

</center>

</body>

</html>


Dat file : contact.dat


1  Isha  65768798  98765432  Daughter

2  Megha  65235689  87654329  Mother


PHP file :


<?php

                $fp = fopen('contact.dat','r');

                echo "<table border=1>";

                echo "<tr><th>Sr. No.</th><th>Name</th><th>Residence No.</th><th>Mob. no.</th><th>Relation</th></tr>";

             

while($row =  fscanf($fp,"%s %s %s %s %s"))

                {

                                echo "<tr>";

                                foreach($row as $r)

                                {

                                                echo "<td>$r</td>";                           

                                }                           

                                echo "</tr>";

                }

                                echo "</table>";

                fclose($fp);

?

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:-


 <!DOCTYPE html>

<html>

<head>

    <title>Live Name Check</title>

    <script>

        function checkName() {

            var name = document.getElementById("nameInput").value;

            var xhr = new XMLHttpRequest();

            xhr.onreadystatechange = function() {

                if (xhr.readyState === 4 && xhr.status === 200) {

                    document.getElementById("response").innerHTML = xhr.responseText;

                }

            };

            xhr.open("GET", "check.php?name=" + name, true);

            xhr.send();

        }

    </script>

</head>

<body>

    <input type="text" id="nameInput" onkeyup="checkName()">

    <div id="response"></div>

</body>

</html>

check.php

<?php

    $name = $_GET["name"];

    

    $specialNames = array("Rohit", "Virat", "Dhoni", "Ashwin", "Harbhajan");


    if (empty($name)) {

        echo "Stranger, please tell me your name!"; 

    } else if (in_array($name, $specialNames)) {

        echo "Hello, master " . $name . "!";

    } else {

        echo $name . ", I don't know you!";

    }

?>


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:-

getTeacherDetails.html

 <html>

 <head>

 <script>

 function showTeacher(str) {

 var xhttp;

 if (str == "") {

 document.getElementById("teacherDetails").innerHTML = "";

 return;

 }

 xhttp = new XMLHttpRequest();

 xhttp.onreadystatechange = function() {

 if (this.readyState == 4 && this.status == 200) {

 document.getElementById("teacherDetails").innerHTML = this.responseText;

 }

 };

 xhttp.open("GET", "getTeacherDetails.php?name="+str, true);

 xhttp.send();

 }

 </script>

 </head>

 <body>

 <form>

 <select name="teachers" onchange="showTeacher(this.value)">

 <option value="">Select a teacher:</option>

 <?php

 $con = mysqli_connect("localhost","my_user","my_password","my_db");

 $sql = "SELECT tname FROM teacher";

 $result = mysqli_query($con,$sql);

 while ($row = mysqli_fetch_array($result)) {

 echo "<option value='" . $row['tname'] ."'>" . $row['tname'] ."</option>";

 }

 mysqli_close($con);

 ?>

 </select>

 </form>

 <br>

 <div id="teacherDetails"><b>Details will be listed here.</b></div>

 </body>

</html>

//PHP Script getTeacherDetails.php

<?php

 $name = $_REQUEST['name'];

 $con = mysqli_connect("localhost","my_user","my_password","my_db");

 $sql = "SELECT * FROM teacher WHERE tname = '$name'";

 $result = mysqli_query($con,$sql);

 while ($row = mysqli_fetch_array($result)) {

 echo "<b>Teacher Number:</b> " . $row['tno'] . "<br>";

 echo "<b>Name:</b> " . $row['tname'] . "<br>";

 echo "<b>Qualification:</b> " . $row['qualification'] . "<br>";

 echo "<b>Salary:</b> " . $row['salary'] . "<br>";

 }

 mysqli_close($con);

?>

Database

Create database college

Create table teacher(tno int primary key,tname varchar(20),qualificationvarchar(10),salary int);

Insert 3 records


2. 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:-

 Create Table customer(cno int primary key,cname varchar(20),city varchar(20));

Create Table order(cno int references customer(cno),ono primary key,odate date,shipadd varchar(20));


<?php 

$cname=$_POST['cname'];

$con=pg_connect("host=localhost dbname=minal user=root") or die("could not connect");

$qry="select cname,city from customer,order where customer.cno=order.cno and cname=$cname"; $rs=pg_query($con,$qry) or die("Unable to execute query");

if($rs!=null) { echo"<table border=0>";

echo "<tr><td>Customer Name</td><td>City</td></tr>";

while($row=pg_fetch_row($rs))

 { echo "<tr>";

echo "<td>".$row[0]."</td>";

echo "<td>".$row[1]."</td>";

 echo "</tr>"; }

echo "</table>";

} else echo "No records found";

 pg_close($con);

?>

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:-

 <html>

<head>

<script type="text/javascript">

function suggest()

{

 var arr = ["apple","banana","mango","orange","strawberry","grapes"];

 var suggest = "";

 var input = document.getElementById("txt1").value;

 for(i=0;i<arr.length;i++)

 {

 if(arr[i].substring(0,input.length).toLowerCase() == input.toLowerCase())

 {

 suggest = suggest+" "+arr[i];

 }

 }

 document.getElementById("txt2").innerHTML = suggest;

}

</script>

</head>

<body>

<input type="text" id="txt1" onkeyup="suggest();">

<p>Suggestions: <span id="txt2"></span></p>

</body>

</html>


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:-

 BookInfo.xml

 <?xml version="1.0" encoding="utf-8"?>

 <BookList>

 <Book>

 <Title>The Great Gatsby</Title>

 <Author>F. Scott Fitzgerald</Author>

 <Year>1925</Year>

 <Price>$7.99</Price>

 </Book>

 <Book>

 <Title>To Kill a Mockingbird</Title>

 <Author>Harper Lee</Author>

 <Year>1960</Year>

 <Price>$8.99</Price>

 </Book>

 <Book>

 <Title>The Catcher in the Rye</Title>

 <Author>J.D. Salinger</Author>

 <Year>1951</Year>

 <Price>$9.99</Price>

 </Book>

 </BookList>

Html file :

<!DOCTYPE html>

<html lang="en">

<head>

 <title>Document</title>

</head>

<body>

 <script>

 function getBookDetails(bookName) {

 var xhttp = new XMLHttpRequest();

 xhttp.onreadystatechange = function() {

 if (this.readyState == 4 && this.status == 200) {

 var xmlDoc = this.responseXML;

 var book = xmlDoc.getElementsByTagName("Book");

 for (var i = 0; i < book.length; i++) {

 if (book[i].getElementsByTagName("Title")[0].childNodes[0].nodeValue == bookName) {

 alert("Author: " + book[i].getElementsByTagName("Author")[0].childNodes[0].nodeValue + "\n"

+

 "Year: " + book[i].getElementsByTagName("Year")[0].childNodes[0].nodeValue + "\n" +

 "Price: " + book[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue);

 }

 }

 }

 };

 xhttp.open("GET", "BookInfo.xml", true);

 xhttp.send();

 }

 // Call the getBookDetails function

 getBookDetails("The Catcher in the Rye");

 </script>

</body>

</html>

 

 

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>-----------";

}

?>