Web Technology Submission
Web Technology Submission
CERTIFICATE
This is to certify that Patel Nidhi Dhirubhai bearing enrolment number 180180107046has
satisfactorily completed the term work under the program B.E Computer engineering of 6th
2020.
Submission Date:-1/05/2021
Sign of Faculty
1
180180107046 NIDHI PATEL WEB PROGRAMMING
INDEX
Practical Title Page
No. No.
1. Design a web page using different text formatting tags to print 4
Helloworld in bold & italic font..
2. Write an HTML program that demonstrates different heading 6
stylesand paragraph.
3. Write HTML codes to attach audio video on webpage using 7
embed tagin html.
4. Design a web page with hyperlinks to different pages and 9
allownavigation between web pages.
5. Write an HTML program to demonstrate the use of ordered list 11
andunordered list with its type. (Circle, disk, square)
6. Create an HTML page with frames that divides the page in 3 14
equalparts. One of the frames contain an image.
7. Design a web page with Image tag. 15
8. Design a web page with different tables. Design a webpages using 16
table so that the content appears well placed.
9. Design a web page with a form that uses all types of input 21
elements (textbox ,radio button, checkox, dropdown,buttonetc)
10. Design a simple web page using HTML5 semantic elements. 24
11. Write a program that prints factorial/Fibonacci series. 27
12. Design a form and validate all the controls placed on the form 29
using Java Script.
13. Write a JavaScript program to display given number is prime or 30
not.
14. Write a JavaScript program to accept a number from the user 33
anddisplay the sum of its digits.
15. Write a java script program to design simple calculator. 35
16. Write a PHP Program to accept a number from the user and print 38
it factorial.
17. Write a PHP program to accept a number from the user and 39
printwhether it is prime or not.
18. Write a PHP code to find the greater of 2 numbers. Accept the 41
no.from the user.
19 Write a PHP program to demonstrate different string functions. 43
20. Write a PHP code to find the greater of 2 numbers. Accept the 46
no.from the user.
21 Write a PHP program to demonstrate different PHP functions. 47
22 Write a PHP program to create one dimensional array. 50
23. Write a PHP code to create: Create a database College. 51
Create a table Department (Dname, Dno, Number_Of_faculty)
24. Write a PHP program to create a database named “College”. 53
Create a table named “Student” with following fields
(sno, sname, percentage).Insert 10 records of your
choice.
2
180180107046 NIDHI PATEL WEB PROGRAMMING
3
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL :-1
AIM: Design a web page using different text formatting tags to print Hello world in bold and
italic font.
❖ Tags:
1) <!DOCTYPE>
• The <!DOCTYPE> defines a document type.
2) <html>
• The <html> tag defines on HTML Document.
3) <head>
• The <head> tag defines information for a document.
4) <title>
• The <title> tag defines a title for a document.
5) <body>
• The <body> tag defines the document’s body.
6) <b>
• The <b> tag defines abold text.
7) <br>
• The <br> tag defines a single line break.
8) <i>
• The <i> tag defines italic text.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>hello world</title>
</head>
<body>
<b><i><h1>HELLO WORLD</h1></i></b>
4
180180107046 NIDHI PATEL WEB PROGRAMMING
</body>
</html>
❖ OUTPUT:
5
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 2
AIM: Write an HTML program that demonstrates different heading style and paragraph.
❖ Tags:
9) <h1> to <h6>
• The <h1> to <h6> tags defines HTML heading.
10) <p>
• The <p> tag defines a paragraph.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>style and paragraph</title>
</head>
<body>
<h1>this is heading1</h1><br>
<h2>this is heading2</h2><br>
<h3>this is heading3</h3><br>
<h4>this is heading4</h4><br>
<h5>this is heading5</h5><br>
<h6>this is heading6</h6><br>
<p>this is paragraph</p>
</body>
</html>
❖ OUTPUT:
6
180180107046 NIDHI PATEL WEB PROGRAMMING
7
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 3
AIM: Write HTML codes to attach audio video on webpage using embed tag in html.
❖ Tags:
11) <embed>
• The <em> tag is defines a container for an external application.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>audio and video</title>
</head>
<body>
❖ OUTPUT:
8
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 4
AIM: Design a web page with hyperlinks to different pages and allow navigation between
web pages.
❖ Tags:
12) <ol>
• The <ol> tag defines an ordered list.
13) <li>
• The <li> tag defines a list item.
14) <a>
• The <a> tag defines a hyperlink.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>hyperlink</title>
</head>
<body>
<nav>
<ul>
<li><a href="3.html">practical 3</a></li>
<li><a href="2.html">practical 2</a></li>
<li><a href="1.html">practical 1</a></li>
</ul>
</nav>
</body>
</html>
9
180180107046 NIDHI PATEL WEB PROGRAMMING
❖ OUTPUT:
10
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 5
AIM: Write an HTML program to demonstrate the use of ordered list and unordered list with
its type. (Circle, disk, square)
❖ Tags:
15) <ul>
• The <ul> tag defines an unordered list.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>list</title>
</head>
<body>
<ol type="1">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ol>
<ol type="A">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ol>
<ol type="a">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
11
180180107046 NIDHI PATEL WEB PROGRAMMING
</ol>
<ol type="I">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ol>
<ol type="i">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ol>
<ul type="square">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ul>
<ul type="disk">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ul>
<ul type="circle">
<li>tea</li>
<li>coffee</li>
<li>milk</li>
</ul>
</body>
</html>
❖ OUTPUT:
12
180180107046 NIDHI PATEL WEB PROGRAMMING
13
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 6
AIM: Create an HTML page with frames that divides the page in 3 equal parts. One of the
frames contain an image.
❖ Tags:
16) <iframe>
• The <iframe> tag defines an inline frame.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>frameset</title>
</head>
<frameset cols="*,*,*" border="4px;"><hr>
<frame src="p1.html">
<frame src="p2.jpg">
<frame src="p3.html"></frame>
</frameset>
<body>
</body>
</html>
❖ OUTPUT:
14
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 7
❖ Tags:
17) <img>
• The <img> tag defines a HTML image.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>use of image tage</title>
</head>
<body>
<h1><center>GOVERNMENT ENGINEERING
COLLAGE,DAHOD</center></h1>
<center><img src="logo.jpg" ></center>
</body>
</html>
❖ OUTPUT:
15
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 8
AIM: Design a web page with different tables. Design a webpages using table so that the
content appears well placed.
❖ Tags:
18) <table>
• The <table> tag defines a table.
19) <caption>
• The <caption> tag defines a table caption.
20) <tr>
• The <tr> tag defines a row in a table.
21) <th>
• The <th> tag defines a header cell in a table.
22) <td>
• The <td> tag defines a cell in a table.
❖ CODE:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<title>time table</title>
</head>
<body>
<center>
<table border="1" cellspacing="0;" style="text-align: center; ">
<caption>
<h3>GOVERNMENT ENGINEERING COLLEGE, DAHOD</h3>
<h4>COMPUTER ENGINEERING DEPARTMENT</h4>
<h5>TIME TABLE EVEN 2020-2021</h5>
16
180180107046 NIDHI PATEL WEB PROGRAMMING
<tr>
<th>TIME</th>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THE</th>
<th>FRI</th>
<th>SAT</th>
</tr>
<tr>
<td>10:30 to 11.30</td>
<td>LECT :4TH PEM,5107</td>
<td> </td>
<td> LECT :6TH WP,5107</td>
<td> LECT :6TH WP,5119</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>11:30 to 12.30</td>
<td>LECT :4TH PEM,5107</td>
<td> </td>
<td> </td>
<td> </td>
17
180180107046 NIDHI PATEL WEB PROGRAMMING
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7"> <center>BREAK </center></td>
</tr>
<tr>
<td>1.15 TO 2.15</td>
<td rowspan="2">LAB:6TH BDE,5114</td>
<td rowspan="2">LAB:6TH C DE,5114</td>
<td></td>
<td rowspan="2"> LAB:6TH ADE,5114</td>
<td>LECT :4TH PEM,5107</td>
<td rowspan="2">LAB:6TH DDE,5114</td>
</tr>
<tr>
<td>2:15 to 3:15</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7"> <center> BREAK </center></td>
</tr>
<tr>
<td> 3:30 to 4:30 </td>
18
180180107046 NIDHI PATEL WEB PROGRAMMING
<td> </td>
<td rowspan="2"> LAB:4 TH ADE,5114 </td>
<td rowspan="2">LAB:4 TH CDE,5114 </td>
<td> </td>
<td> LECT :6TH WP,5119</td>
<td rowspan="2"> LAB:6 TH DDE,5114 </td>
</tr>
<tr>
<td>4:30 TO 5:30</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>5.30 TO 6.30</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</center>
</table>
</body>
</html>
19
180180107046 NIDHI PATEL WEB PROGRAMMING
❖ OUTPUT:
20
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 9
AIM: Design a web page with a format that uses all types of input elements (textbox, radio
button, checkbox, dropdown, button etc.)
❖ Tags:
23) <center>
• The <center> tag defines centered text.
24) <u>
• The <u> tag defines some text that is unarticulated and styled differently
from normal text.
25) <form>
• The <form> tag defines an HTML form for user input.
26) <textarea>
• The <textarea> defines a multiline input control.
27) <input>
• The <input> tag defines an input control.
Tags Description
<input type=””radio”> Displays a radio button.
<input type=”checkbox”> Display a checkbox.
<input type=”submit”> Display a submit button.
<input type=”reset”> Display a reset button.
28) <select>
• The <select> tag defines a drop-down list.
29) <option>
• The <option> tag defines an option in a drop-down list.
❖ CODE
<!DOCTYPE html>
<html>
<head>
<title>form</title>
</head>
<body>
21
180180107046 NIDHI PATEL WEB PROGRAMMING
<input type="submit">
<input type="reset">
</fieldset>
</form>
</body>
</html>
❖ OUTPUT:
22
180180107046 NIDHI PATEL WEB PROGRAMMING
23
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 10
❖ Tags:
30) <style>
• The <style> tag defines style information for a document.
31) <section>
• The <section> tag defines a section in a document.
32) <aside>
• The <aside> tag defines content aside from the page content.
33) <article>
• The <article> tag defines an article.
34) <figure>
• The <figure> tag specifies self-contained content.
35) <header>
• The <header> tag defines a header for a document or section.
36) <footer>
• The <footer> tag defines a footer for a document or section.
37) <main>
• The <main> tag specifies the main content of a document.
38) <nav>
• The <nav> tag defines a navigation links.
39) <details>
• The <details> tag defines additional details that the user can view or hide.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<section>
24
180180107046 NIDHI PATEL WEB PROGRAMMING
<h1>CLASS A</h1>
<p>Since only 1 byte in class A defines the netid and the leftmost bit should be 0, the
next 7 bits can bechanged to find the number of blocks in this class.
Therefore, class A is divided into 27 = 128 blocks that can be assigned to 128
organizations (the number is less because some blocks were reserved as special
blocks).
However, each block in this class contains 16,777,216 addresses, which means the
organization should be a really large one to use all these addresses.
Many addresses are wasted in this class. Figure 5.9 shows the block in class A.
</p>
</section>
<section>
<h1>CLASS B</h1>
next 7 bits can bechanged to find the number of blocks in this class.
Therefore, class A is divided into 27 = 128 blocks that can be assigned to 128
organizations (the number is less because some blocks were reserved as special
blocks).
However, each block in this class contains 16,777,216 addresses, which means the
organization should be a really large one to use all these addresses.
Many addresses are wasted in this class. Figure 5.9 shows the block in class A.
</p>
</section>
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008.
Chrome is the world's most popular web browser today!</p>
</article>
<article>
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox
has been the second most popular web browser since January, 2018.</p>
</article>
<nav>
<a href="www.google.com">html</a>
<a href="www.facebook.com">facebook</a>
<a href="www.instagram.com">instagram</a>
</nav>
<footer>
<p>author:hege refsnes</p>
<a href="[email protected]">mailid</a>
</footer>
<figure>
<img src="coffee.jpg" height="50px">
25
180180107046 NIDHI PATEL WEB PROGRAMMING
<figcaption>coffee</figcaption>
</figure>
<details>
<summary>Epcot Center</summary>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting
attractions, international pavilions, award-winning fireworks and seasonal special
events.</p>
</details>
</body>
</html>
OUTPUT:
26
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 11
❖ Tags:
40) <script>
• The <script> tag defines a client-side script
.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>factorial of 5</p>
<button onclick = "fact()"> ans </button>
<script>
function fact(){
var i, num=5, fact;
fact = 1;
if(num>0)
{
for(i = 1; i <= num; i++)
{
fact = fact * i;
}
document.write(fact);
}
else
{
document.write("invalid");
}
document.write(fact());
}
</script>
</body>
</html>
27
180180107046 NIDHI PATEL WEB PROGRAMMING
OUTPUT:
28
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 12
AIM: Design a form and validate all the controls placed on the form using Java Script.
❖ Tags:
41) <script>
• The <script> tag defines a client-side script
❖ CODE:
<html>
<head>
<title>Form Validation</title>
<script type = "text/javascript">
function validate() {
}
if( document.myForm.EMail.value == "" ) {
alert( "Please provide your Email!" );
}
if( document.myForm.Zip.value == "" || isNaN(
document.myForm.Zip.value ) ||
document.myForm.Zip.value.length <= 5 ) {
}
if( document.myForm.Country.value == "-1" ) {
alert( "Please provide your country!" );
}
//-->
</script>
</head>
29
180180107046 NIDHI PATEL WEB PROGRAMMING
<body>
<form action = "asdsrecvb" name = "myForm" onsubmit =
"return(validate());">
<fieldset style="width: 15%"><legend >data colletion form</legend>
Name: <input type = "text" name = "Name" ><br><br>
❖ OUTPUT:
30
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 13
❖ Tags:
42) <button>
• The <button> tag defines a clickable button.
❖ CODE:
<!DOCTYPE html>
<html>
<head><title>Practical 13</title>
<script>
function Prime()
{
vari,flag=0,number;
number = Number(document.getElementById("N").value);
31
180180107046 NIDHI PATEL WEB PROGRAMMING
</html>
❖ OUTPUT:
32
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 14
AIM: Write a Java Script program to accept a number from the user and display the sum of
its digits.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var n=1234;
var sum=0;
while(n>0)
{
sum=sum+n%10;
n=Math.floor(n/10);
}
alert(sum);
</script>
</body>
</html>
❖ OUTPUT:
33
180180107046 NIDHI PATEL WEB PROGRAMMING
34
180180107046 NIDHI PATEL WEB PROGRAMMING
Practical 15
❖ Tags:
43) <div>
• The <div>tag defines a section in a document.
❖ CODE:
<!DOCTYPE html>
<html>
<head>
<title>Practical 15</title>
<script>
function dis(val)
{
document.getElementById("edu").value+=val
}
function solve()
{
let x = document.getElementById("edu").value
let y = eval(x)
document.getElementById("edu").value = y
}
functionclr()
{
document.getElementById("edu").value = ""
}
</script>
<style type="text/css">
body,html
{
matgin:0px;
}
input[type="button"]
{
border:none;
35
180180107046 NIDHI PATEL WEB PROGRAMMING
width:100%;
outline: none;
}
#wrap
{
margin:10%;
}
</style>
</head>
<body>
<div class = title align="center">JavaScript Calculator</div>
<table border="1" align="center">
<tr>
<td><input type="button" value="c" onclick="clr()"/></td>
<td colspan="3"><input type="text" id="edu"/></td>
</tr>
<tr>
36
180180107046 NIDHI PATEL WEB PROGRAMMING
❖ OUTPUT:
37
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 16
AIM: Write a PHP Program to accept a number from the user and print it factorial.
CODE:
<!DOCTYPE html>
<html>
<body>
<?php
$num = 9;
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
echo "Factorial of $num is $factorial";
?>
</body>
</html>
❖ OUTPUT:
38
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 17
AIM: Write a PHP program to accept a number from the user and print whether it is prime or
not.
CODE:
<html>
<head>
<title>Prime number</title>
</head>
<body>
<form method="post">
<table>
<tr>
<td>enter a number</td>
<td><input type="text" name="number"/></td>
</tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="submit"/>
</tr>
</table>
</form>
</body>
<?php
if(isset($_POST['submit']))
{
$number=$_POST['number'];
$primeFlag=0;
for($i=2;$i<$number;$i++)
{
$primeFlag=0;
if(($number%$i)==0)
{
break;
}
$primeFlag=1;
}
if($primeFlag==1)
{
echo "$number is prime number";
}else{
echo "$number is not prime number";
39
180180107046 NIDHI PATEL WEB PROGRAMMING
}
}
?>
</html>
40
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 18
AIM: Write a PHP program to find the greater or two numbers. Accept the no. from the user.
CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$number1=2020;
$number2=20;
if ($number1>$number2)
else
?>
</body>
</html
41
180180107046 NIDHI PATEL WEB PROGRAMMING
42
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 19
CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
echo("convert lowercase");
echo("<br>");
$str="MY NAME IS KHAN";
$str=strtolower($str);
echo("<br>");
echo $str;
echo("<br>");
echo("-----------------------------------------------------------");
echo("<br>");
echo("convert uppercase");
echo("<br>");
$str="My name is khan";
echo("<br>");
$str=strtoupper($str);
echo("<br>");
echo $str;
echo("<br>");
43
180180107046 NIDHI PATEL WEB PROGRAMMING
echo("-----------------------------------------------------------");
echo("<br>");
echo("converting first character into uppercase");
echo("<br>");
$str="my name is KHAN";
echo("<br>");
$str=ucfirst($str);
echo $str;
echo("<br>");
echo("-----------------------------------------------------------");
echo("<br>");
echo("converting first character into lowercase");
echo("<br>");
$str="my name is KHAN";
echo("<br>");
$str=lcfirst($str);
echo $str;
echo("<br>");
echo("-----------------------------------------------------------");
echo("<br>");
?>
</body>
44
180180107046 NIDHI PATEL WEB PROGRAMMING
</html>
45
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 20
AIM: Write a PHP code to find the greater of 2 numbers. Accept the no. from the user.
CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$number1=2020;
$number2=20;
if ($number1>$number2)
{
echo " $number1 is a max .";
}
else
{
echo "$number2 is max";
}
?>
</body>
</html
OUTPUT:
46
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 21
CODE:
//user define function
<!DOCTYPE html>
<html>
<body>
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg();
?>
</body>
</html>
//one argument pass function
<!DOCTYPE html>
<html>
<body>
<?php
function familyName($fname) {
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>
</body>
</html>
OUTPUT:
47
180180107046 NIDHI PATEL WEB PROGRAMMING
48
180180107046 NIDHI PATEL WEB PROGRAMMING
49
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 22
CODE:
<!DOCTYPE html>
<html>
<body>
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "array is: " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
</body>
</html>
OUTPUT:
50
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 23
AIM: Write a PHP code to create ; create a database college,Create a table
Department(Dname, Dno, Number_of_faculty)
CODE:
<?php
$servername = "localhost";
$username = "root";
$password = '';
$dbname = 'college';
// Create connection
$conn = new mysqli($servername, $username, $password , $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " );
$sql = "CREATE DATABASE college";
if ($conn->query($sql) === TRUE)
{
echo "Database created successfully";
}
else {
echo "Error creating database: ";
}
}
// create table name department
$sql = "CREATE TABLE department (
dno INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dname VARCHAR(30) NOT NULL,
number_of_faculty VARCHAR(30) NOT NULL
)";
$conn->close();
?>
51
180180107046 NIDHI PATEL WEB PROGRAMMING
OUTPUT:
52
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 24
53
180180107046 NIDHI PATEL WEB PROGRAMMING
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "sno: " . $row["sno"]. " - sname: " . $row["sname"]. " " . $row["percentage"].
"<br>";
}
} else {
echo "0 results";
}
// Create database
$conn->close();
?>
OUTPUT:
54
180180107046 NIDHI PATEL WEB PROGRAMMING
55
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 25
AIM: Write a PHP code of student ragistation form. Use below four field s in registration
form. (emailed, username, password, confirm password).
Use table form controls.
CODE:
<!doctype html>
<?php
$servername = "localhost";
$username="root";
$password="";
$dbname="college";
try{
$conn = mysqli_connect($servername, $username,$password,$dbname);
echo("<html> <br><center>connected Successfully</center></br></html>");
}catch(MySQLi_Sql_Exception $ex){
echo("error in connection");
}
if(isset($_POST['submit'])){
$email=$_POST['email'];
$username=$_POST['username'];
$pass=$_POST['pass'];
$cpass=$_POST['cpass'];
$register_query = "INSERT INTO register(email, username, pass, cpass) VALUES
('$email', '$username', '$pass', '$cpass')";
try{
$register_result = mysqli_query($conn, $register_query);
if($register_result){
if(mysqli_affected_rows($conn)>0){
echo("<html> <br><center>registration successful</center></br></html>");
}else{
echo("error in registration");
}
}
}catch(Exception $ex){
echo("error".$ex->getMessage());
}
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
56
180180107046 NIDHI PATEL WEB PROGRAMMING
</head>
<body>
<form action="" method="post">
<table align="center">
<tr>
<td>email:</td>
<td><input type="email" name="email"
placeholder="[email protected]"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>username:</td>
<td><input type="text" name="username" placeholder="enter your username"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="pass" value="admin"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>confirm password:</td>
<td><input type="password" name="cpass" value="admin"></td>
</tr>
57
180180107046 NIDHI PATEL WEB PROGRAMMING
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="SignUp"></td>
</tr>
</table>
</form>
</body>
</html>
OUTPUT:
58
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 26
AIM: Write a PHP code of student login form who registered in previous practical no. 25.
CODE:
<?php
$servername = "localhost";
$username="root";
$password="";
$dbname="college";
try{
$conn = mysqli_connect($servername, $username,$password,$dbname);
echo("<html> <br><center>connected Successfully</center></br></html>");
}catch(MySQLi_Sql_Exception $ex){
echo("error in connection");
}
if (isset($_POST['submit']))
{
$result = mysqli_query($conn,$query);
if (mysqli_num_rows($result) >= 1) {
$row = mysqli_fetch_array($result);
echo "inside";
header("Location: welcome.php");
else{
echo"<center> wrong username or password</center>";
}
//If result matched $myusername and $mypassword, table row must be 1 row
59
180180107046 NIDHI PATEL WEB PROGRAMMING
else{
}
?>
<html>
<head>
<title>Login Page</title>
</head>
</div>
</div>
</div>
</body>
</html>
60
180180107046 NIDHI PATEL WEB PROGRAMMING
OUTPUT:
61
180180107046 NIDHI PATEL WEB PROGRAMMING
PRACTICAL 27
?>
<form action="cookie_1.php" method="post" style="border: 2px dotted blue; text-
align:center; width: 400px;">
<p>
Username: <input name="username" type="text" value="<?php
if(isset($_COOKIE["username"])) { echo $_COOKIE["username"]; } ?>"
class="input-field">
</p>
<p>Password: <input name="password" type="password"
value="<?php if(isset($_COOKIE["password"])) { echo $_COOKIE["password"]; }
?>" class="input-field">
</p>
<p><input type="checkbox" name="remember" /> Remember me
</p>
<p><input type="submit" value="Login"></span></p>
</form>
<?php
if(!empty($_POST["remember"])) {
$user=$_POST['username'];
setcookie ("username",$_POST["username"],time()+ 3600);
setcookie ("password",$_POST["password"],time()+ 3600);
echo "<html> <center>Cookies Set Successfuly</center></html>";
echo " <html> <center>
your username is :.$user
</center></html>";
} else {
setcookie("username","");
setcookie("password","");
echo "<html> <center>Cookies Not Set </center></html>";
}
?>
62
180180107046 NIDHI PATEL WEB PROGRAMMING
63
180180107046 NIDHI PATEL WEB PROGRAMMING
?>
<!DOCTYPE html>
<html>
<body>
//code for session1
<?php
// Set session variables
$_SESSION["username"] = "nidhi";
$_SESSION["pass"] = "patel";
echo "<html><center>Session variables are set. </center></html>";
?>
<p><center><a href="session1.php"> go to access session </center></a> </p>
</body>
</html>
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous page
echo "your username is " . $_SESSION["username"] . ".<br>";
echo "your password is " . $_SESSION["pass"] . ".";
?>
</body>
</html>
64
180180107046 NIDHI PATEL WEB PROGRAMMING
Output:
65