Sie sind auf Seite 1von 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:

Das könnte Ihnen auch gefallen