0% found this document useful (0 votes)
185 views

Vivek Burungale Roll No: 1964114 Course - MSC (Ca) Semester: 2 Subject: Web Programming 2 Assignment No - 7

This document contains 3 programming assignments for a Web Programming 2 course. The first assignment involves creating an XML file to store book details and using AJAX to retrieve and display the details of a selected book. The second assignment involves creating a database in 3NF to store employee and department data, and using PHP to display a salary statement for a given department. The third assignment uses AJAX to retrieve and display teacher details from a PostgreSQL database table based on a selected teacher name.

Uploaded by

VivekBurungale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views

Vivek Burungale Roll No: 1964114 Course - MSC (Ca) Semester: 2 Subject: Web Programming 2 Assignment No - 7

This document contains 3 programming assignments for a Web Programming 2 course. The first assignment involves creating an XML file to store book details and using AJAX to retrieve and display the details of a selected book. The second assignment involves creating a database in 3NF to store employee and department data, and using PHP to display a salary statement for a given department. The third assignment uses AJAX to retrieve and display teacher details from a PostgreSQL database table based on a selected teacher name.

Uploaded by

VivekBurungale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

VIVEK BURUNGALE

Roll No: 1964114

COURSE – Msc (CA)

Semester : 2

Subject: Web Programming 2

Assignment No - 7
Assignment No 7

1. 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, and price).

Program Code :

<html>
<body>
<h3>BOOK INFORMATION</h3>
<form method="POST">
Enter BOOK Name :<input type=text name=b_name id=b_name><br><br>
<br>
<input type=submit value="Submit">
</form>
</body>
</html>
<?php
try {
$b_name = $_POST['b_name'];
getBookInforamtion($b_name);
} catch (Exception $e) {
echo "<br>";
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
pg_close();
function getBookInforamtion($b_name)
{
try {

$xmldata = simplexml_load_file("./book.xml") or die("Failed to load");

$book = $xmldata->book;
echo "<br>";
echo "Book Information : <b>" . $b_name . "</b>";
echo "<br>";
echo "<br>";
echo "<table
border=1><tr><td><b>TITLE</b></td><td><b>AUTHOR</b></td><td><b>PRICE</b></td></
tr>";
foreach ($book->title as $title) {
if ($title == $b_name) {

echo "<tr><td>" . $book->title . "</td><td>" . $book->author . "</td><td>" . $book-


>price . "</td></tr>";
}
}
} catch (Exception $e) {
echo "<br>";
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
}
?>

OUTPUT:

XML DATA:

<?xml version="1.0"?>
<library>
<book>
<title>JAVA</title>
<author>WROX</author>
<year>1998</year>
<price>500</price>
</book>
<book>
<title>PHP</title>
<author> Alan Forbes</author>
<year>2010</year>
<price>250</price>
</book>
</library>
2. Consider the following entities and their relationships Emp
(emp_no,emp_name,address,phone,salary) Dept (dept_no,dept_name,location)Dept -emp are
related with one-many relationship Create a RDB in 3NF for the above and solve following
Using above database write a PHP script which will print a salary statement in the
format given below, for a given department. (Accept department name from the
user).

Program Code:

<html>
<head>
<script type="text/javascript">
function search(str) {
var ob = false;
ob = new XMLHttpRequest();
ob.open("GET", "q2_2_7.php?q=" + str);
ob.send();
ob.onreadystatechange = function() {
if (ob.readyState == 4 && ob.status == 200)
document.getElementById("txtSearch").innerHTML = ob.responseText;
}
}
</script>
</head>

<body>
<h3>SEARCH STUDENT</h3>
<form>
Enter Name Of Student :<input type=text name=search size="20"
onkeyup=search(form.search.value)>
</form> RESULT :<span id="txtSearch"></span><br>
</body>
</html>

q2_2_7.php

<?php
$input_array = array("VIVEK", "SANDESH", "ROHAN", "RAGINI", "AKSHAY", "PRAGYA",
"AJAY", "SAMEER", "ADDY");
$search_string = $_GET['q'];
if (strlen($search_string) > 0) {
$match = "";
for ($i = 0; $i < count($input_array); $i++) {
if (strtolower($search_string) == strtolower(substr($input_array[$i], 0,
strlen($search_string)))) {
if ($match == "") {
$match = $input_array[$i];
} else {
$match = $match . "," . $input_array[$i];
}
}
}

if ($match == "") {
echo "Not Found";
} else {
echo $match;
}
}

OUTPUT:
3. Write an AJAX program to print Teacher information from postgreSQL table
Teacher.
Teacher (Tno, Name, Subject, Research area).

Program Code:

<html>
<body>
<h3>TEACHER INFORMATION</h3>
<form method="POST">
Enter Teacher Name :<input type=text name=t_name id=t_name><br><br>
<br>
<input type=submit value="Submit">
</form>
</body>
</html>
<?php
require_once 'dbconfig.php';
$con_string =
"pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
try {
$pdo = new PDO($con_string);
if ($conn) {
echo "Connected to the <strong>$db</strong> database successfully!";
}
$t_name = $_POST['t_name'];
getTeacherInforamtion($t_name, $pdo);
} catch (Exception $e) {
echo "<br>";
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
pg_close();
function getTeacherInforamtion($t_name, $pdo)
{
try {
$sql = 'select name, subject, research_area from teacher WHERE name=' . "'" . $t_name . "'";
$stmt = $pdo->query($sql);
echo "<br>";
echo "Teacher Information : <b>" . $t_name . "</b>";
echo "<br>";
echo "<br>";
echo "<table
border=1><tr><td><b>NAME</b></td><td><b>SUBJECT</b></td><td><b>RESEARCH
AREA</b></td></tr>";
while ($row = $stmt->fetch()) {
echo "<tr><td>" . $row[0] . "</td><td>" . $row[1] . "</td><td>" . $row[2] .
"</td></tr>";
}
} catch (Exception $e) {
echo "<br>";
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
}
?>

Table Name: Teacher


tno SERIAL PRIMARY KEY,
name varchar(50),
subject varchar(50),
research_area varchar(50)

OUTPUT:

You might also like