Вы находитесь на странице: 1из 44

PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

WEB TECHNOLOGIES LAB MANUAL

EXCERCISE 1:

HOME PAGE:
The static home page must contain three frames.
Top frame : Logo and the college name and links to Home page, Login page, Registration
page, Catalogue page and Cart page (the description of these pages will be given below).
Left frame : At least four links for navigation, which will display the catalogue of respective
links.
Right frame: The pages to the links in the left frame must be loaded here. Initially this page
contains description of the web site.

homepage.html

<frameset rows="25%,*">
<frame src="topframe.html" scrolling=no>
<frameset cols="20%,*">
<frame src="leftframe.html" >
<frame src="rightframe.html" name="rframe">
</frameset>
</frameset>

topframe.html

<html>
<head><title>top frame</title>
</head>
<body bgcolor="yellow" text="blue">
<table border="1" width="100%">
<tr>
<th width="15%"><img src="E:\WT Lab\Ex1\logo.jpg" height=50 width=100>
<th colspan=4 ><center><h1> QIS BOOK STORE</h1></center>
</tr>
</table>
<table border="1" width="100%">
<tr>
<th><a href="E:\WT Lab\Ex1\rightframe.html" target="rframe">home</a>
<th><a href="E:\WT Lab\Ex1\login.html" target="rframe">login</a>
<th><a href="E:\WT Lab\Ex1\registration.html" target="rframe">registration</a>
<th><a href="E:\WT Lab\Ex1\cat.html" target="rframe">Catalogue</a>
<th><a href="E:\WT Lab\Ex1\cart.html" target="rframe">Cart</a>
</tr>
</table>
<table width=100%>
<marquee direction=right><h3> <a href="E:\WT Lab\Ex1\registration.html"
target="rframe">New user... register here</a> </h3></marquee>
</table></body></html>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 1


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

leftframe.html

<html>
<head>
<title>leftframe</title>
</head>
<body bgcolor="orange" text="green">
<table border=1 height="100%" width="100%">
<tr>
<th><a href="E:\WT Lab\Ex1\cse.html" target="rframe">cse</a>
</tr>
<tr>
<th><a href="E:\WT Lab\Ex1\ece.html" target="rframe">ece</a>
</tr>
<tr>
<th><a href="E:\WT Lab\Ex1\eee.html" target="rframe">eee</a>
</tr>
<tr>
<th><a href="E:\WT Lab\Ex1\mech.html" target="rframe">mech</a>
</tr>
<tr>
<th><a href="E:\WT Lab\Ex1\it.html" target="rframe">it</a>
</tr>
<tr>
<th><a href="E:\WT Lab\Ex1\civil.html" target="rframe">civil</a>
</tr>
</table>
</body>
<html>

rightframe.html
<html>
<head><title>right frame</title>
</head>
<body bgcolor="pink" text="white">
<center><h1> About QIS Book Store</h1></center>
<p>
QIS Book store is the one of the best book store for Engineering books. This book store
provides the official information about Course Material and provides several options by
which students are able to purchase or rent what they need
</p>
<br>
<br>
<p>
QIS Book Store have 100s of volumes of books for all engineering branches. It is a backbone
for QIS College of Engineering and Technology. It indicates the quality and service of an
academic institution.
</p>
</body>
</html>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 2


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 3


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 2:

Design a static user login page for the online book store website with
1. loginid (textfield)
2. password (password field)
3. Two buttons (Submit and Reset)

HTML CODE:

login.html

<html>
<head>
<title>login</title>
</head>
<body bgcolor="blue" text="white">
<center>
<table>
<tr> <td>loginid
<td><input type="text" size=20>
</tr>
<tr> <td>password
<td><input type="password" size=20>
</tr>
</table>
<input type="button" value="submit">
<input type="button" value="reset">
</center>
</body></html>

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 4


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 3:
CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the web site in
a table.
The details should contain the following:
1. Snap shot of Cover Page.
2. Author Name.
3. Publisher.
4. Price.
5. Add to cart button.

HTML Code:

catalogue.html

<html>
<head><title>Catalogue</title>
</head>
<body bgcolor="red" text="white">
<center>
<h1> <U>List of Books Available</U></h1>
<table border="1">
<thead>
<tr>
<th>Cover Page
<th>Title
<th>Author
<th>Publisher
<th>Price
<th>Qunatity
<th>Cart
</tr>
</thead>
<tbody>
<tr>
<td><img src="E:\WT Lab\Ex1\c.jpg" height=50 width=50>
<td>Let Us C
<td>Yeswanth Kanethkar
<td>PHI
<td>500
<td>10
<td><input type="button" value="Add to Cart">
</tr>
<tr>
<td><img src="E:\WT Lab\Ex1\bee.jpg" height=50 width=50>
<td> Basic Electrical Engineering
<td>V K Mehta
<td> S Chand
<td>300
<td>25

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 5


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<td><input type="button" value="Add to Cart">


</tr>
<tr>
<td><img src="E:\WT Lab\Ex1\edc.jpg" height=50 width=50>
<td>Electronic Devices and Circuit Theory
<td> Rober L Boylestad
<td> TMH
<td>459
<td>34
<td><input type="button" value="Add to Cart">
</tr>
<tr>
<td><img src="E:\WT Lab\Ex1\eg.jpg" height=50 width=50>
<td>Engineering Graphics
<td>B K Goel
<td>OXFORD
<td>279
<td>15
<td><input type="button" value="Add to Cart">
</tr>
</tbody>
</table>
</center>
</body>
</html>

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 6


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 4:

REGISTRATION PAGE:
Create a registration form with the following fields
1) Name (Text field)
2) Password (password field)
3) E-mail id (text field)
4) Phone number (text field)
5) Sex (radio button)
6) Date of birth (3 select boxes)
7) Languages known (check boxes English, Telugu, Hindi, Tamil)
8) Address (text area)

HTML Code:

Registration.html

<html>
<head><title>Registration</title>
</head>
<body bgcolor="purple" text="white">
<h3> New User Rgister here</h3>
<center>
<table border=1>
<tr> <td> Name
<td> <input type="text" size=20>
</tr>
<tr> <td> Password
<td> <input type="password" size=20>
</tr>
<tr> <td> Email id
<td> <input type="text" size=20>
</tr>
<tr> <td> phone number
<td> <input type="text" size=20>
</tr>
<tr> <td> Gender
<td> <input type="radio" name="gender">male
<input type="radio" name="gender">female
</tr>
<tr>
<td> Date of Birth
<td>
<select name="date">
<option>1
<option>2
<option>3
<option>4
<option>5
<option>6

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 7


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<option>7
<option>8
<option>9
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
<option>31
</select>
<select name="month">
<option>jan
<option>feb
<option>mar
<option>apr
<option>may
<option>jun
<option>Jul
<option>Aug
<option>Sep
<option>Oct
<option>Nov
<option>Dec
</select>
<select name="year">
<option>1995
<option>1996
<option>1997
</select>
</tr>
<tr> <td> languages known
<td> <input type="checkbox">English
<input type="checkbox">Hindi
<input type="checkbox">Tamil

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 8


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<input type="checkbox">Telugu
</tr>
<tr>
<td> Address
<td> <textarea cols=20 rows=5></textarea>
</tr>
</table>
<input type="button" value="submit">
<input type="button" value="reset">

</center>
</body>
</html>

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 9


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 5:

Design a web page using CSS (Cascading Style Sheets) which includes the following:
Use different font, styles.

Source Code:

<html>
<head>
<title>css</title>
<style>
p{color:green;background-color:lightblue;font-size:30pt}
.p1{font-size:10pt;color:orange;background-color:white}
.p2{font-size:20pt;color:blue}
a:link{font-size:30pt;color:red}
a:visited{font-size:30pt;color:purple}
a:hover{font-size:30pt;color:magenta}
a:active{font-size:30pt;color:blue}
body {background-image:url("c.jpg")}

</style>
</head>
<body>
<p class="p1">In modern website development, CSS programming is a service on

demand. CSS helps web design and development professionals to add fonts,

colors and other formatting to web pages. Developed and maintained by the

World Wide Web Consortium, CSS helps web developers to separate content from

design and save a lot of working time. Prior to CSS, the presentational

elements of HTML docs were contained within the HTML markup. All colors,

styles, borders, fonts, etc had to be repeatedly described within the HTML

file. CSS allows creating a simpler HTML file and move the formatting

information to separate file.</p>


<p>Cascading Style Sheets CSS is one of the most useful and helpful tools web

designers and web developers use to build professional websites with unique

look and feel. CSS gives many great options allowing enhancing the website

design and functioning. Take a glance at some of WOWEB projects using CSS

Cascading Style Sheets. </p>


<p class="p2">CSS (Cascading Style Sheets) enables the separation of HTML

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 10


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

document from document presentation, such as layout, colors, fonts. Styles are

stored in .css files enabling web masters to change website layout by editing

one single file. There are Author Style Sheets (created by the web page

author); User Style Sheets (set by the web page user); User Agent Style Sheets

(styles applied by the web browser to display the web page).<p>


<center><a href="E:\WT Lab\Ex1\bookstore.html" target="_blank">Click here to

search for CSS Book</a><center>


</body>
</html>

OUTPUT:

EXERCISE 6:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 11


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

Design a dynamic webpage using Javascript for illustrating arithmetic operators.

Source Code:

<html>
<head>
<title>Arithmetic Operators </title>
<script>
function add()
{
var a=document.arithmetic.first.value;
var b=document.arithmetic.second.value;
var c=parseInt(a)+parseInt(b);
document.arithmetic.result.value=c;
}
function sub()
{
var a=document.arithmetic.first.value;
var b=document.arithmetic.second.value;
document.arithmetic.result.value=a-b;
}
function mul()
{
var a=document.arithmetic.first.value;
var b=document.arithmetic.second.value;
document.arithmetic.result.value=a*b;
}
function div()
{
var a=document.arithmetic.first.value;
var b=document.arithmetic.second.value;
document.arithmetic.result.value=a/b;
}
</script>
<style>
table {background-color:pink}

</style>
</head>
<body background="as.jpg" text="darkblue">
<br><br><br><br><br><br><br>
<center>

<form name="arithmetic">
<table border=1>
<tr>
<td align="center" colspan=2><h1> Javascript Arithmetic Operators
Demo </h1>
</tr>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 12


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<tr>
<td><h2>First Numeber</h2>
<td><input type="text" size=50 name="first">
</tr>
<tr>
<td><h2>Second Numeber</h2>
<td><input type="text" size=50 name="second">
</tr>
<tr>
<td><h2>Result</h2>
<td><input type="text" size=50 name="result">
</tr>
<tr >
<h2>
<td colspan=2 align=center>
<input type="button" value="Add" onclick="add()">
<input type="button" value="Subtract" onclick="sub()">
<input type="button" value="Multiply" onclick="mul()">
<input type="button" value="Divide" onclick="div()">
</h2>
<tr>
<table>
</form>
<center>
</html>

OUTPUT:

EXERCISE 7:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 13


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

Write an XML file which will display the Book information which
includes the following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above
XML file.

Source Code:

XML document (bookstore.xml)

<bookstore>
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&amp;ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 14


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

XML document Validation using DTD


DTD document (bookstore.dtd)

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


<!ELEMENT bookstore (book+)>
<!ELEMENT book (title,author,ISBN,publisher,edition,price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>

Bookstore.xml
<!DOCTYPE bookstore SYSTEM "C:\Documents and Settings\Administrator\My
Documents\bookstore.dtd">
<bookstore>
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&amp;ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 15


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

XML document Validation using DTD


XML Schema (bookstore.xsd)

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

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"


xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"></xs:element>
<xs:element name="author" type="xs:string"></xs:element>
<xs:element name="ISBN" type="xs:string"></xs:element>
<xs:element name="publisher" type="xs:string"></xs:element>
<xs:element name="edition" type="xs:int"></xs:element>
<xs:element name="price" type="xs:decimal"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Bookstore.xml
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\My
Documents\bookstore.xsd">
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 16


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&amp;ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>

Display the XML file as follows.

XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="bookstore.xsl"?>

<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 17


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<price>39.95</price>
</book>
</bookstore>
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2> My Books collection</h2>
<table border="1">
<tr bgcolor="red">
<th align="left">title</th>
<th align="left">author</th>
</tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price &gt; 30">
<td bgcolor="yellow"><xsl:value-of select="author"/></td>
</xsl:when>
<xsl:when test="price &gt; 10">
<td bgcolor="magneta"><xsl:value-of select="author"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="author"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 18


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 19


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 8:

PHP program for simple CONTACTUS page.

Source Code:

contactus.html

<html>
<body text="blue">
<center>
<h1> Contact @ QISCET</h1>
<img src="contactus.jpg" height=30% width=100%>
<form action="contact.php" method="GET">
<h3>Name<br>
<input type="text" name="name" size=50><br>
Mailid<br>
<input type="text" name="email" size=50><br>
Subject<br>
<input type="text" name="subject" size=50><br>
Message<br>
<textarea cols=50 rows=20 name="message">Your message here....!
</textarea><br>
<input type="submit" value="send" name="submit">
</h3>
</form>
<center>
</body>
</html>

contact.php

<?php
$n=$_GET['name'];
$e=$_GET['email'];
$m=$_GET['message'];
if($n==""||$e==""||$m=="")
echo "fill all the required data...!";
else
echo "Your message sent successfully... Thank you for your interest in
us!";
?>

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 20


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 21


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 9:

PHP program for registering users of a website and login.

Source Code:

registration.html

<html>
<body bgcolor="red" text="white">
<center>
<img src="Reg.jpg" height=20% width=50%>
<form name="f" method="get" action="reg.php" onsubmit="reg()">
<table>
<tr>
<td>First Name
<td><input type="text" name="fname">
</tr>
<tr>
<td>Last Name
<td><input type="text" name="lname">
</tr>
<tr>
<td>User Id
<td><input type="text" name="uid"><br>
</tr>
<tr>
<td>Password
<td><input type="password" name="pwd">
</tr>
<tr>
<td>Confirm Password
<td><input type="password" name="cp">
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Register">
<input type="reset" value="Cancel">
</tr>
</form>
</center>
</html>

reg.php:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 22


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<?php
$f=$_GET['fname'];
$l=$_GET['lname'];
$u=$_GET['uid'];
$p=$_GET['pwd'];
$con=mysqli_connect("localhost","root","","Authorized");
if($con)
{
$query="insert into users values('$f','$l','$u','$p')";
$result=mysqli_query($con,$query);
if($result)
echo "You have registered successfully...<a href=login.html>Click here to
login</a>";
}
?>

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 23


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

login.html

<html>
<script>
</script>
<body bgcolor="green" text="white">
<center>
<h1> User Login</h1>

<form name="log" action="login.php" method="get">


<table>
<tr>
<td> UserId
<td> <input type="text" name="lid">
</tr>
<tr>
<td>Password
<td> <input type="password" name="p">
</tr>
<tr>
<td colspan=2 align="center"> <input type="submit" value="login">
</tr>
</table>
</form>
</body>
</html>

login.php:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 24


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

<?php
$l=$_GET['lid'];
$p=$_GET['p'];
$con=mysqli_connect("localhost","root","","Authorized");
if($con)
{
$query="Select userid, password from users where userid='$l' and password='$p'";
$result=mysqli_query($con,$query);
if($result)
{
$row=mysqli_fetch_array($result);
if($row['userid']==$l and $row['password']==$p)
echo "Welcome $l, You are the authorized user...!";
else
echo "You are not an authorized user... Please register";
}
}
?>

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 25


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 10:

Write a PHP program to insert data from PHP to MySQL.

Source Code:

<?php
$con=mysqli_connect("localhost","root","","User");
if($con)
{
$query="insert into Users values

('user1','password1','user1@mail.com','9999999999'),

('user2','password2','user2@mail.com','9888888888'),

('user3','password3','user3@mail.com','9877777777'),
('user4','password4','user4@mail.com','9876666666'),
('user5','password5','user5@mail.com','9876555555')";
$result=mysqli_query($con,$query);
if($result)
echo "Data Inserted successfully.....!";

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 26


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

?>
OUTPUT:

EXERCISE 11:

Write a PHP program to extract data from MySQL data base and display it

Source Code:

<?php
$con=mysqli_connect("localhost","root","","User");
if($con)
{
$query="select * from users";
$result=mysqli_query($con,$query);
if($result)
{
echo "<center>The Results extracted from MySQL";
echo "<table border=1><tr><td>User Name<td>Password<td>Email<td>Phone

Number</tr>";
while($row=mysqli_fetch_array($result))
{
echo "<tr><td>$row[UserName]<td>$row[Password]<td>$row[MailId]<td>

$row[Phone]</tr>";
}

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 27


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

echo "</table></center>";
}
}?>

OUTPUT:

EXERCISE 12:

Write a program which illustrates the use of associative arrays in perl.

Source Code:

#!usr/bin/perl
%ceo=('yahoo'=>"Marissa Mayer",'google'=>"Sundar Pichai", 'infosys'=>"Vishal
Shikka",'HCL'=>"Anant Gupta",'TCS'=>"Rajesh Gopinathan");
@company=keys(%ceo);
@ceos=values(%ceo);
$size=@company.length;

for($i=0;$i<$size;$i++)
{
print $ceos[$i]." is the CEO of ".$company[$i]."\n";
}

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 28


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 13:

Write perl program takes a set names along the command line and prints their file type.

Source Code:

#!usr/bin/perl
$len = @ARGV;
for ($i=0;$i<$len;$i++)
{
if(-e $ARGV[$i])
{
if(-T $ARGV[$i])
{
print "$ARGV[$i] is a text file\n";
}
else
{
print "$ARGV[$i] is a special file\n";
}

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 29


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

}
else
{
print "$ARGV[$i] does not exists\n";
}
}

OUTPUT:

EXERCISE 14:

Write a perl program to implement UNIX `passwd' program

Source Code:

my $salt='';
my $encrypted='';
my $password='';
my $use = 'Usage: Please provide password for encrypt';
my @saltchars=('.', '/', 0..9, 'A'..'Z', 'a'..'z');
my $args=@ARGV;
if ( $args < 1 || $args > 2 )
{
print "$use\n";
exit;
}
$password=$ARGV[0];
if( $args == 1 )

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 30


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

{
$salt = join('',@saltchars[rand(64),rand(64)]);

}
else
{
$salt=$ARGV[1];
}
$encrypted=crypt($password,$salt);
print "$password --> $encrypted\n";

OUTPUT:

EXERCISE 15:

Write a perl program to connect to a MySQl database table and


execute simple commands.

Source Code:
use DBI;
$db="cse";
$host="localhost";
$user="root";
$password="";

#connect to MySQL database


my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",$user,
$password)
or die "Can't connect to database: $DBI::errstr\n";
#prepare the query
my $sth = $dbh->prepare( "SELECT *FROM students");

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 31


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

#execute the query


$sth->execute();

## Retrieve the results of a row of data and print


print "\tQuery results:\n=====================\n";
print("ROLL\tNAME\tBRANCH\n=====================\n");
while (my @row = $sth->fetchrow_array())
{
print "@row\n";
}
warn "Problem in retrieving results", $sth->errstr( ), "\n" if $sth->err();
exit;
OUTPUT:

EXERCISE 16:

Write Ruby program reads a number and calculates the factorial


value of it and prints the same.

Source Code:

puts "enter a number to find the factorial"


n=Integer(gets)
f=n
fact=1
while n!=0 do
fact=fact*n
n-=1
end
puts "the factorial of the #{f} is #{fact}"

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 32


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

OUTPUT:

EXERCISE 17:

Write a Ruby program which counts number of lines in a text file


using its regular expressions facility.

Source Code:

#! usr/bin/ruby

print "Enter file name:";


fname = gets.chomp;
count = IO.readlines(fname).size
puts "There are #{count} lines in #{fname}";

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 33


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

OUTPUT:

EXERCISE 18:

Write a Ruby program to illustrate the use of Ruby Iterators

Source Code:
puts "1.each"
puts "2.times"
puts "3.step"
puts "4.upto"
puts "5.downto"
puts "enter your choice"
ch=gets.to_i

case ch
when 1

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 34


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

(1..9).each do |i|
puts i
end
when 2
5.times do
puts "cse"
end
when 3
0.step(10,2) do |i|
puts i
end
when 4
5.upto(10) do |i|
puts i
end
when 5
10.downto(5) do |i|
puts i
end
end

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 35


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 19:

Write a Ruby program that uses iterator to find out the length of
a string.

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 36


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

Source Code:

#!usr/bin/ruby

puts "enter the string"

str=gets.chomp.split("")
count=0

str.each do |i|
count+=1
end

puts "the size of the string is #{count}"

OUTPUT:

EXERCISE 20:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 37


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

Write a Ruby program to sort the given set of numbers using


Bubble Sort

Source Code:

#!usr/bin/ruby

a=Array.new()
puts "How many elements the array can hold?"
size=gets.to_i
puts "What are elements.... Enter them"
for i in 0..size-1 do
a[i]=gets.to_i
end

for i in 0..size-1 do
for j in i..size-1 do
if a[i]>a[j]
t=a[i]
a[i]=a[j]
a[j]=t
end
end
end
puts "Sorting was done... Now the contents of array are"
puts a

OUTPUT

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 38


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 21:

Write a Ruby program for performing Linear search

Source Code:

#! usr/bin/ruby

college=["cse","ece","eee","mech","it","civil"]

puts "enter branch name to search"

branch=gets.chomp

if college.include?(branch)
puts "College is offering branch #{branch}"
else
puts "Collge is not offering branch #{branch}"
end

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 39


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 22:

Write a Ruby program to illustrate the use of Associative Arrays

Source Code:

#!usr/bin/ruby

state={:ap=>"Amaravathi",:ts=>"Hyderabad",:tn=>"chennai"}
puts "The capital of Andhra pradesh is #{state[:ap]}"
puts "The capital of Telangana state is #{state[:ts]}"
puts "The capital of Tamilanadu is #{state[:tn]}"
state[:ka]="Bengaluru"
state[:mh]="Mumbai"
state[:kl]="Thiruvanantapuram"
puts "the states in the hash after adding karnataka, maharshtra, Kerala
are"
puts state
state.delete(:kl)
puts "the states in the hash after deleting Kerala are"
puts state
OUTPUT

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 40


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 23:

Write a Ruby program that calculates the area of triangle using


Math module

Source Code:

#!usr/bin/ruby
puts "enter values for a, b, c"
a=Integer(gets)
b=Integer(gets)
c=Integer(gets)
s=(a+b+c)/2
tarea=Math.sqrt(s*(s-a)*(s-b)*(s-c))
puts "The area of triangle is #{tarea}"

OUTPUT

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 41


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 24:

Write Ruby program which uses tk module to display a window

Source Code:

require 'tk'
root = TkRoot.new { title "Ex1" }
TkLabel.new(root) {
text 'Hello, World!'
pack { padx 15 ; pady 15; side 'left' }
}
Tk.mainloop

OUTPUT

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 42


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

EXERCISE 25:

Define complex class in Ruby and do write methods to carry


operations on complex objects.

Source Code:

#! usr/bin/ruby
c1=Complex(2,3)
c2=Complex(4,5)

puts "The sum of 2+3i and 4+5i:"


puts c1+c2
puts "The Difference of 2+3i and 4+5i:"
puts c1-c2
puts "The product of 2+3i and 4+5i:"
puts c1*c2
puts "The result of division of 2+3i and 4+5i:"
puts c1/c2

OUTPUT:

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 43


PREPARED BY TVN SUDHEER, ASSISTANT PROFESSOR, DEPARTMENT OF CSE

QIS COLLEGE OF ENGINEERING AND TECHNOLOGY, ONGOLE 44

Вам также может понравиться