Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 50

Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-19

Aim:- To create PHP program for contact us page


Program:-
mail.html

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body bgcolor="lightgreen">
<center><form action="mail_handler.php" method="post">
<br><br><br>First Name: <input type="text" name="first_name"><br>
<br>Last Name: <input type="text" name="last_name"><br>
<br>Email: &nbsp&nbsp<br><textarearows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="submit" value="reset">
</form></center>
</body>
</html>
mail_handler.php
<?php
if(isset($_POST['submit'])){
$to = "email@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other. }?>
php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = you@yoursite.com

Srinivasa Institute of Engg. & Tech. 1


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Output:-

Result:-

Srinivasa Institute of Engg. & Tech. 2


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-20

Aim:- User Authentication :Assume four users user1,user2,user3 and user4 having the passwords
pwd1,pwd2,pwd3 and pwd4respectively. Write a PHP for doing the following.
1. Create a Cookie and add these four user id’s and passwords to this Cookie.
2. Read the user id and passwords entered in the Login form (week1) and authenticate with the
values(user id and passwords ) available in the cookies.If he is a valid user(i.e., user-name and
password match) you should welcome him by name(user-name) elseyou should display “ You are not
an authenticated user ’’.Use init-parameters to do this.
Program:-

coklogcheck.html
<html>
<title>website</title>
<head></head>
<body bgcolor="lightgreen">
<form method="POST" name="frmlogin" action="coklogcheck.php">
<br><br><br><br><br><br><br><center><table border="0">
<tr>
<td><b><i><font size=5>Login:</font></i></b></td>
<td><input name="Uname" type="text" ></td>
</tr>
<tr>
<td><b><i><font size=5>PassWord:</font></b></i></td>
<td><input name="password" type="password" ></td>
</tr>
<tr>
<input type="hidden" name="hdnProcess" value="1"/>
<td><input type="submit" name="sbt" value="Submit"/></td>
<td><input type="button" name="res" value="Reset"/></td>
</tr>
</table></center>
</form>
</body>
</html>
coklogcheck.php
<?php
//if(!empty($_POST['hdnProcess']))
//{
setcookie("user1","yesu");
setcookie("user2","blessy");
setcookie("user3","anusha");
setcookie("user4","madhavi");
setcookie("pass1","jyothi");
setcookie("pass2","giri");
setcookie("pass3","rekha");
setcookie("pass4","devi");

Srinivasa Institute of Engg. & Tech. 3


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

$UserId = $_POST['Uname'];
$passwd = $_POST['password'];
// setcookie("UserId", $_POST['Uname']);
// setcookie("Passwd", $_POST['password']);
if(($_COOKIE['user1']==$UserId&&$_COOKIE['pass1']==$passwd)||
($_COOKIE['user2']==$UserId&&$_COOKIE['pass2']==$passwd)||
($_COOKIE['user3']==$UserId&&$_COOKIE['pass3']==$passwd)||
($_COOKIE['user4']==$UserId && $_COOKIE['pass4']==$passwd ) )
{ echo "<h1>success</h1>"; }
else
{ echo "<h1>Login Failed</h1>";
//setcookie("UserId",NULL,NULL);
//setcookie("passwd",NULL,NULL);
}
//}
?>

Output:-

Srinivasa Institute of Engg. & Tech. 4


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Result:-

Srinivasa Institute of Engg. & Tech. 5


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-21

Aim:- To create PHP program for registering users of a website and login.

Description:
Initially create a person table with username, password, email, phno and address in database.
In this application, we fill and send the registration form details to the person
table of MySql database, if it is success otherwise which gives registration failed.
Here registration file will be loaded into the browser after clicking on hyperlink Registration
of top_frame.html. Fill the registration form and submit these details.
Database receives registration form details from request object and sends to the person table of the
MySql database through insert query after establish connection to database.
In this application we validate given username and password with already registered users. If
it is valid, which displays welcome with username otherwise which displays invalid user with login
form.Here login.html file will be loaded into the browser after clicking on hyperlink Login of
top_frame.html. Fill the login form and submit their details .
Login.php establishes the connection between the application and database which compares
username and password of login form with all usernames and passwords of person table of the oracle
database. If there are valid username and password, then display welcome with username otherwise
display invalid use

Program:-

regvalidate.html

<html>
<head>
<title>Registration</title>
<script type="text/javascript">
function validateall()
{
var flag=false;
if(validateName())
{
if(validatepassword())
{
if(validateemail())
{
if(validatephno())
{
flag=true;
}
}
}
}
return flag;
}
function validateName()
{

Srinivasa Institute of Engg. & Tech. 6


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

var x=document.myform.sname.value;
if(x==null||x=='')
{
alert("Please enter Name");
return false;
}
if(x.length<6)
{
alert("Name should contain atleast 6 characters");
return false;
}
var namepattern=/[a-z]/i;
if(!namepattern.test(x))
{
alert("enter valid name that contains only characters");
return false;
}
return true;
}
function validatepassword()
{
var x=document.myform.password.value;
if(x==null||x=='')
{
alert("Please enter the Password");
return false;
}

if(x.length<6)
{
alert("Password should contain atleast 6 characters");
return false;
}
return true;
}
function validateemail()
{
var x=document.myform.email.value;
var emailpattern=/^[a-zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{3}$||^[a-
zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{2}.[a-zA-Z][a-zA-Z0-9]{2}$/;
if(x==null||x=='')
{
alert("Please enter the Email");
return false;
}
if(x.length<6)
{
alert("email address should not contain less than 6 characters ");
return false;
}
if(!emailpattern.test(x))

Srinivasa Institute of Engg. & Tech. 7


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

{
alert("Enter valid email address");
return false;
}
return true;
}
function validatephno()
{
var x=document.myform.phno.value;
var phnopattern=/[0-9]/;
if(x==null||x=='')
{
alert("Please enter the Phone number");
return false;
}
if(x.length>10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(x.length<10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(!phnopattern.test(x))
{
alert("enter valid phone number");
return false;
}
return true;
}
</script>
</head>
<body bgcolor="lightgreen">
<form name="myform" onsubmit="return validateall();" method="post" action="login.html">
<table border="0" align="center">
<tr>
<td>Name: </td>
<td><input type="text" name="sname" size="25" maxlength="35" ></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" size="25" maxlength="15" ></td>
</tr>
<tr>
<td>E-mail id: </td>
<td><input type="text" name="email" size="25" maxlength="35"></td>
</tr>
<tr>
<td>phone number: </td>

Srinivasa Institute of Engg. & Tech. 8


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

<td><input type="text" name="phno" size="25" maxlength="12"></td></tr>


<tr>
<td><input type="submit" value="submit" name="ten" ></td>
<td><input type="reset" value="Reset" name="eleven"></td>
</tr>
</table>
</form>
</body>
</html>

Output:-

Srinivasa Institute of Engg. & Tech. 9


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

login.html

<html>
<head>
<title>Login</title>
</head>
<body bgcolor="pink">
<br><br><br><br><br><br><form method="post" action="hello.html">
<table border="0" cellspacing="5" align="center">
<tr>
<td>Login-ID:</td>
<td><input type="text" name="one" size="16" maxlength="15"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="two" size="16" maxlength="15"></td>
</tr>
<tr>
<td align="right"><input type="submit" value="GO" name="three"></td>
<td align="left"><input type="reset" value="CLEAR" name="four"></td>
</table>
</form>
</body>
</html>

Output:-

Srinivasa Institute of Engg. & Tech. 10


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

hello.html
<html>
<head>
<title>Hello</title>
</head>
<body bgcolor="lightblue">
<br><br><br><marquee behavior="slide"><center><h1><font color="maroon">U ARE
WELCOME</font></h1></center></marquee>
</body>
</html>
Output:-

Result:-

Srinivasa Institute of Engg. & Tech. 11


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-22

Aim:- To install a database(Mysql or Oracle).


Create a table which should contain at least the following fields: name, password, email-id,
phonenumber(these should hold the data from the registration form).
Write a PHP program to connect to that database and extract data from the tables and display
them.Experiment with various SQL queries.
Insert the details of the users who register with the web site, whenever a new user clicks the submit
button in the registration page (week2).
Description:
Initially create a person table with username, password, email, phno and address in database.
In this application, we fill and send the registration form details to the person
table of MySql database, if it is success otherwise which gives registration failed.
Here registration file will be loaded into the browser after clicking on hyperlink Registration
of top_frame.html. Fill the registration form and submit these details.
Database receives registration form details from request object and sends to the person table of the
MySql database through insert query after establish connection to database.

Program:-
homepage.html
<html>
<head>
<title>HOME PAGE</title>
<frameset rows="30%,*" frameborder="1">
<frame name="webtitle" src="webtitle.html">
<frameset cols="237,*" frameborder="1">
<frame name="course" src="course.html">
<frame name="main" src="main.html">
</frameset>
</frameset>
<body bground="bookshop.jpg">
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 12


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

webtitle.html
<html>
<head>
<LINK href="Website.css" rel="stylesheet" type="text/css">
<title>HOME</title>
</head>
<body bgcolor="lightpink">
<table width="100%" border="2">
<tr>
<td width="70" bgcolor="black">
<img src="bslogo.gif" alt="LOGO" width="100" height="70"/></td>
<td bgcolor="black"><center>
<img src="onlinebookshop1.jpg" alt="siet" heigth="50" width="600"/></center></td>
</tr>
</table>
<table width="100%" border="2">
<tr align="center" >
<td width="200"><a href="main.html" target="main">HOME</a></td>
<td width="200"><a href="login.html" target="main">LOGIN</a></td>
<td width="200"><a href="registrationpage.html" target="main">REGISTRATION</a></td>
<td width="200"><a href="catalog.html" target="main">CATALOGUE</a></td>
<td width="200"><a href="cart page.html" target="main">CART</a></td>
</tr>
</table>
</body>
</html>
Output:-

sqlcreatedb.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)

Srinivasa Institute of Engg. & Tech. 13


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE firstdb4",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
Output:-

sqlcreatetable.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("firstdb4", $con);
$sql = "CREATE TABLE person
(
Name varchar(15),
Password varchar(15),
Email varchar(15),
PhoneNo varchar(15)
)";
// Execute query
mysql_query($sql,$con);
echo "Table created" . mysql_error();
mysql_close($con);
?>

Srinivasa Institute of Engg. & Tech. 14


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Output:-

sqlinsert.php
<html>
<head>
<title>Registration</title>
<script type="text/javascript">
function validateall()
{
var flag=false;
if(validateName())
{
if(validatepassword())
{
if(validateemail())
{
if(validatephno())
{
flag=true;
}
}
}
}
return flag;
}
function validateName()
{
var x=document.myform.sname.value;
if(x==null||x=='')
{

Srinivasa Institute of Engg. & Tech. 15


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

alert("Please enter Name");


return false;
}
if(x.length<6)
{
alert("Name should contain atleast 6 characters");
return false;
}
var namepattern=/[a-z]/i;
if(!namepattern.test(x))
{
alert("enter valid name that contains only characters");
return false;
}
return true;
}
function validatepassword()
{
var x=document.myform.password.value;
if(x==null||x=='')
{
alert("Please enter the Password");
return false;
}
if(x.length<6)
{
alert("Password should contain atleast 6 characters");
return false;
}
return true;
}

function validateemail()
{
var x=document.myform.email.value;
var emailpattern=/^[a-zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{3}$||^[a-
zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{2}.[a-zA-Z][a-zA-Z0-9]{2}$/;
if(x==null||x=='')
{
alert("Please enter the Email");
return false;
}
if(x.length<6)
{
alert("email address should not contain less than 6 characters ");
return false;
}
if(!emailpattern.test(x))
{
alert("Enter valid email address");

Srinivasa Institute of Engg. & Tech. 16


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

return false;
}
return true;
}
function validatephno()
{
var x=document.myform.phno.value;
var phnopattern=/[0-9]/;
if(x==null||x=='')
{
alert("Please enter the Phone number");
return false;
}

if(x.length>10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(x.length<10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(!phnopattern.test(x))
{
alert("enter valid phone number");
return false;
}
return true;
}
</script>
</head>
<body bgcolor="lightgreen">
<form name="myform" onsubmit="return validateall();" method="post" action="insert.php">
<table border="0" align="center">
<tr>
<td>Name: </td>
<td><input type="text" name="sname" size="25" maxlength="35" ></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" size="25" maxlength="15" ></td>
</tr>
<tr>
<td>E-mail id: </td>
<td><input type="text" name="email" size="25" maxlength="35"></td>
</tr>
<tr>
<td>phone number: </td>
<td><input type="text" name="phno" size="25" maxlength="12"></td>

Srinivasa Institute of Engg. & Tech. 17


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

</tr>
<tr><td><input type="submit" value="submit" name="ten" ></td>
<td><input type="reset" value="Reset" name="eleven"></td>
</tr></table></form></body></html>

insert.php
<html>
<body bgcolor="lightgreen">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("firstdb4", $con);
$sql ="INSERT INTO person VALUES('" . $_POST['sname'] . "' ,'" . $_POST['password'] . "','" .
$_POST['email'] . "','" . $_POST[phno] . "')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo " registration success 1 record added";
$result =mysql_query("SELECT * FROM person");
echo "<center>
<table border=1><tr><td>NAME</td><td>PASSWORD</td><td>EMAIL</td><td>PHONE
NUMBER</td></tr>";
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['Name'] ."</td>";
echo "<td>".$row['Password'] ."</td>";
echo "<td>".$row['Email'] ."</td>";
echo "<td>".$row['PhoneNo'] ."</td>";
echo "</tr>";
}
echo "</table></center>";
mysql_close($con);
?>
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 18


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Srinivasa Institute of Engg. & Tech. 19


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Result:-

Srinivasa Institute of Engg. & Tech. 20


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-23

Aim:- To create a PHP which does the following job:


Insert the details of the 3 or 4 users who register with the web site (week9) by using registration
form.Authenticate the user when he submits the login form using the user name and password from
the database( similar to week8 instead of cookies).
Description:
Initially create a person table with username, password, email, phno and address in database.
In this application, we fill and send the registration form details to the person
table of MySql database, if it is success otherwise which gives registration failed.
Here registration file will be loaded into the browser after clicking on hyperlink Registration
of top_frame.html. Fill the registration form and submit these details.
Database receives registration form details from request object and sends to the person table of the
MySql database through insert query after establish connection to database.
In this application we validate given username and password with already registered users. If
it is valid, which displays welcome with username otherwise which displays invalid user with login
form.Here login.html file will be loaded into the browser after clicking on hyperlink Login of
top_frame.html. Fill the login form and submit their details .
Login.php establishes the connection between the application and database which compares
username and password of login form with all usernames and passwords of person table of the oracle
database. If there are valid username and password, then display welcome with username otherwise
display invalid use
Program:-

homepage.html
<html>
<head>
<title>HOME PAGE</title>
<frameset rows="30%,*" frameborder="1">
<frame name="webtitle" src="webtitle.html">
<frameset cols="237,*" frameborder="1">
<frame name="course" src="course.html">
<frame name="main" src="main.html">
</frameset>
</frameset>
<body bground="bookshop.jpg">
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 21


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

webtitle.html
<html>
<head>
<LINK href="Website.css" rel="stylesheet" type="text/css">
<title>HOME</title>
</head>
<body bgcolor="lightpink">
<table width="100%" border="2">
<tr>
<td width="70" bgcolor="black">
<img src="bslogo.gif" alt="LOGO" width="100" height="70"/></td>
<td bgcolor="black"><center>
<img src="onlinebookshop1.jpg" alt="siet" heigth="50" width="600"/></center></td>
</tr>
</table>
<table width="100%" border="2">
<tr align="center" >
<td width="200"><a href="main.html" target="main">HOME</a></td>
<td width="200"><a href="login.html" target="main">LOGIN</a></td>
<td width="200"><a href="registrationpage.html" target="main">REGISTRATION</a></td>
<td width="200"><a href="catalog.html" target="main">CATALOGUE</a></td>
<td width="200"><a href="cart page.html" target="main">CART</a></td>
</tr>
</table>
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 22


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

sqlcreatedb.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE jyothi",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
Output:-

Srinivasa Institute of Engg. & Tech. 23


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

sqlcreatetable.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("jyothi", $con);
$sql = "CREATE TABLE person
(
Name varchar(15),
Password varchar(15),
Email varchar(15),
PhoneNo varchar(15)
)";
// Execute query
mysql_query($sql,$con);
echo "Table created" . mysql_error();
mysql_close($con);
?>

Output:-

sqlinsert.php
<html>
<head>
<title>Registration</title>
<script type="text/javascript">

Srinivasa Institute of Engg. & Tech. 24


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

function validateall()
{
var flag=false;
if(validateName())
{
if(validatepassword())
{
if(validateemail())
{
if(validatephno())
{
flag=true;
}
}
}
}
return flag;
}
function validateName()
{
var x=document.myform.sname.value;
if(x==null||x=='')
{
alert("Please enter Name");
return false;
}
if(x.length<6)
{
alert("Name should contain atleast 6 characters");
return false;
}
var namepattern=/[a-z]/i;
if(!namepattern.test(x))
{
alert("enter valid name that contains only characters");
return false;
}
return true;
}
function validatepassword()
{
var x=document.myform.password.value;
if(x==null||x=='')
{
alert("Please enter the Password");
return false;
}
if(x.length<6)
{
alert("Password should contain atleast 6 characters");
return false;

Srinivasa Institute of Engg. & Tech. 25


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

}
return true;
}

function validateemail()
{
var x=document.myform.email.value;
var emailpattern=/^[a-zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{3}$||^[a-
zA-Z][a-zA-Z0-9_.]*@[a-zA-Z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]{2}.[a-zA-Z][a-zA-Z0-9]{2}$/;
if(x==null||x=='')
{
alert("Please enter the Email");
return false;
}
if(x.length<6)
{
alert("email address should not contain less than 6 characters ");
return false;
}
if(!emailpattern.test(x))
{
alert("Enter valid email address");
return false;
}
return true;
}
function validatephno()
{
var x=document.myform.phno.value;
var phnopattern=/[0-9]/;
if(x==null||x=='')
{
alert("Please enter the Phone number");
return false;
}

if(x.length>10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(x.length<10)
{
alert("phone number must contain 10 digits ");
return false;
}
if(!phnopattern.test(x))
{
alert("enter valid phone number");
return false;

Srinivasa Institute of Engg. & Tech. 26


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

}
return true;
}
</script>
</head>
<body bgcolor="lightgreen">
<form name="myform" onsubmit="return validateall();" method="post" action="insert.php">
<table border="0" align="center">
<tr>
<td>Name: </td>
<td><input type="text" name="sname" size="25" maxlength="35" ></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" size="25" maxlength="15" ></td>
</tr>
<tr>
<td>E-mail id: </td>
<td><input type="text" name="email" size="25" maxlength="35"></td>
</tr>
<tr>
<td>phone number: </td>
<td><input type="text" name="phno" size="25" maxlength="12"></td>
</tr>
<tr><td><input type="submit" value="submit" name="ten" ></td>
<td><input type="reset" value="Reset" name="eleven"></td>
</tr></table></form></body></html>

insert.php
<html>
<body bgcolor="lightgreen">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("firstdb4", $con);
$sql ="INSERT INTO person VALUES('" . $_POST['sname'] . "' ,'" . $_POST['password'] . "','" .
$_POST['email'] . "','" . $_POST[phno] . "')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo " registration success 1 record added";
$result =mysql_query("SELECT * FROM person");
echo "<center>
<table border=1><tr><td>NAME</td><td>PASSWORD</td><td>EMAIL</td><td>PHONE
NUMBER</td></tr>";
while($row=mysql_fetch_array($result))
{

Srinivasa Institute of Engg. & Tech. 27


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

echo "<tr>";
echo "<td>".$row['Name'] ."</td>";
echo "<td>".$row['Password'] ."</td>";
echo "<td>".$row['Email'] ."</td>";
echo "<td>".$row['PhoneNo'] ."</td>";
echo "</tr>";
}
echo "</table></center>";
mysql_close($con);
?>
</body>
</html>

Output:-

Srinivasa Institute of Engg. & Tech. 28


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Srinivasa Institute of Engg. & Tech. 29


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Srinivasa Institute of Engg. & Tech. 30


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

login.html
<html>
<title>website</title>
<head></head>
<body bgcolor="lightgreen">
<form method="POST" name="frmlogin" action="log12.php">
<br><br><br><br><br><br><br><center><table border="0">
<tr>
<td><b><i><font size=5>Login:</font></i></b></td>
<td><input name="sname" type="text" ></td>
</tr>
<tr>
<td><b><i><font size=5>PassWord:</font></b></i></td>
<td><input name="password" type="password" ></td>
</tr>
<tr>
<input type="hidden" name="hdnProcess" value="1"/>
<td><input type="submit" name="sbt" value="Submit"/></td>
<td><input type="button" name="res" value="Reset"/></td>
</tr>
</table></center>
</form>
</body>
</html>

log12.php

<html>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)

Srinivasa Institute of Engg. & Tech. 31


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("firstdb4", $con);
$r="select * from person";
$t=mysql_query($r);
if(mysql_num_rows($t) > 0)
{
while($u=mysql_fetch_array($t))
{
extract($u);
$x=$Name;
$y=$Password;
if($_POST['sname']==$x && $_POST['password']==$y)
{
echo "<center><h1>login success</h1></center> <br>";
echo " <center><h1>WELCOME :$x<h1></center>";

break;
}
}
if($_POST['sname']!=$x && $_POST['password']!=$y)
{
echo " <h1>Login failed u r not an authenticated user</h1>";
}
}
?>
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 32


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Result:-

Srinivasa Institute of Engg. & Tech. 33


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-24

Aim:- To Create tables in the database which contain the details of items (books in our case like
Book name ,Price, Quantity, Amount ) of each category. Modify your catalogue page
(week 2)in such a way that you should connect to the database and extract data from the tables and
display them in the catalogue page using PHP.

Description:
Initially, create a books table with title, author, price and quantity in MySql database. Insert
multiple records into the books table directly at database.
In this application, we will display the available books in the books table by clicking on
hyperlink Catalog .
Here Catalog.php file will load all the books available in the books table of oracle database
after clicking on the hyperlink Catalog of top_framel. At the time of loading catalogue file, which
stores each record details in the hidden form fields.

Program:-

homepage.html
<html>
<head>
<title>HOME PAGE</title>
<frameset rows="30%,*" frameborder="1">
<frame name="webtitle" src="webtitle.html">
<frameset cols="237,*" frameborder="1">
<frame name="course" src="course.html">
<frame name="main" src="main.html">
</frameset>
</frameset>
<body bground="bookshop.jpg">
</body>
</html>
Output:-

webtitle.html
<html>

Srinivasa Institute of Engg. & Tech. 34


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

<head>
<LINK href="Website.css" rel="stylesheet" type="text/css">
<title>HOME</title>
</head>
<body bgcolor="lightpink">
<table width="100%" border="2">
<tr>
<td width="70" bgcolor="black">
<img src="bslogo.gif" alt="LOGO" width="100" height="70"/></td>
<td bgcolor="black"><center>
<img src="onlinebookshop1.jpg" alt="siet" heigth="50" width="600"/></center></td>
</tr>
</table>
<table width="100%" border="2">
<tr align="center" >
<td width="200"><a href="main.html" target="main">HOME</a></td>
<td width="200"><a href="login.html" target="main">LOGIN</a></td>
<td width="200"><a href="registrationpage.html" target="main">REGISTRATION</a></td>
<td width="200"><a href="catalog.html" target="main">CATALOGUE</a></td>
<td width="200"><a href="cart page.html" target="main">CART</a></td>
</tr>
</table>
</body>
</html>
Output:-

sqlcreatedb.php

same as in the week23

sqlcreatetab1.php

<?php
$con = mysql_connect("localhost","root","");

Srinivasa Institute of Engg. & Tech. 35


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("yesu", $con);
// Create table
mysql_select_db("yesu", $con);
$sql = "CREATE TABLE cart(Title varchar(15),Author varchar(15),Price varchar(15),
Quantity varchar(15))";
// Execute query
mysql_query($sql,$con);
echo "Table created" . mysql_error();
mysql_close($con);
?>

Output:-

sqlcreatetable.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("yesu", $con);
// Create table
mysql_select_db("yesu", $con);
$sql = "CREATE TABLE cart(Title varchar(15),Author varchar(15),Price varchar(15),

Srinivasa Institute of Engg. & Tech. 36


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Quantity varchar(15))";
// Execute query
mysql_query($sql,$con);
echo "Table created" . mysql_error();
mysql_close($con);
?>

Output:-

test.php

<?php
$y=mysql_connect("localhost","root","");
mysql_select_db("yesu",$y);
$x="select * from cart";
$res=mysql_query($x);
$var="AddtoCart";
echo "<form method=post action=cart.php>";
echo "<center><h1>Following Books are Available</h1></center>";
$num=1;
echo "<center><table
border=1>"."<tr>"."<th>"."Title"."</th>"."<th>"."Author"."</th>"."<th>"."Price"."</th>"."<th>"."Q
uantity"."</th>"."<th>"."Cart"."</th>"."</tr></center>";
while($val=mysql_fetch_array($res))
{
$str= "btn"+ $num;

Srinivasa Institute of Engg. & Tech. 37


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

echo
"<tr>"."<td>".$val['Title']."</td>"."<td>".$val['Author']."</td>"."<td>".$val['Price']."</td>"."<td>".$
val['Quantity']."</td>"."<td>"."<input
type=button name=$str value=$var>"."</input>"."</td>"."</tr>";
$num++;
}
echo "</form>";
?>

Output:-

cart.php

<html>
<body>
<?php
$y=mysql_connect("localhost","root","");
mysql_select_db("yesu",$y);
echo "<center><h1>Following Books Are Available in our site</h1></center>";
$y="INSERT INTO cart VALUES(&Title,&Author,&Price,&Quantity) ";
$res=mysql_query($y);
$query="SELECT * FROM cart";
$result=mysql_query($query);
echo "<center><table
border=1>"."<tr>"."<th>"."Title"."</th>"."<th>"."Author"."</th>"."<th>"."Price"."</th>"."<th>"."Q
uantity"."</th>"."</tr></center>";
if(mysql_num_rows($result) > 0){
while($value=mysql_fetch_array($result)){
echo
"<tr>"."<td>".$value['Title']."</td>"."<td>".$value['Author']."</td>"."<td>".$value['Price']."
</td>"."<td>".$value['Quantity']."</td>"."</tr>";
}}
?>

Srinivasa Institute of Engg. & Tech. 38


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

</body>
</html>

Output:-

Result:-

Srinivasa Institute of Engg. & Tech. 39


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

WEEK-25

Aim:- HTTP is a stateless protocol. Session is required to maintain the state.


The user may add some items to cart from the catalog page. He can check the cart page for the
selecteditems. He may visit the catalogue again and select some more items. Here our interest is the
selected items should be added to the old cart rather than a new cart. Multiple users can do the same
thing at a time(i.e.,from different systems in the LAN using the ip-address instead of localhost). This
can be achieved through the use of sessions. Every user will have his own session which will be
created after his successful login tothe website. When the user logs out his session should get
invalidated (by using the methodsession.invalidate() ).Modify your catalogue and cart PHP pages to
achieve the above mentioned functionality using sessions

Description:
Initially, create a books table with title, author, price and quantity MySQL database. Insert
multiple records into the books table directly at database.
In this application, we will display the available books in the books table by clicking on
hyperlink Catalogue of top_frame.html. Once we click any add-to-cart button, the corresponding
book will be added to the cart page.
Here Cart.php file will load all the books available in the books table of MySQL database
after clicking on the hyperlink Catalogue of top_frame.html. At the time of loading catalogue file,
which stores each record details in the hidden form fields. Once we click on any add-to-cart button,
that record will be stored in the Http Session interface object in the cart.php file, like wise we can add
many records to the Http Session interface object.
Now we can see the added books through accessing cart1.jsp file by clicking on the hyperlink
cart of top_frame.html

Program:-
homepage.html
<html>
<head>
<title>HOME PAGE</title>
<frameset rows="30%,*" frameborder="1">
<frame name="webtitle" src="webtitle.html">
<frameset cols="237,*" frameborder="1">
<frame name="course" src="course.html">
<frame name="main" src="main.html">
</frameset>
</frameset>
<body bground="bookshop.jpg">
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 40


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

webtitle.html
<html>
<head>
<LINK href="Website.css" rel="stylesheet" type="text/css">
<title>HOME</title>
</head>
<body bgcolor="lightpink">
<table width="100%" border="2">
<tr>
<td width="70" bgcolor="black">
<img src="bslogo.gif" alt="LOGO" width="100" height="70"/></td>
<td bgcolor="black"><center>
<img src="onlinebookshop1.jpg" alt="siet" heigth="50" width="600"/></center></td>
</tr>
</table>
<table width="100%" border="2">
<tr align="center" >
<td width="200"><a href="main.html" target="main">HOME</a></td>
<td width="200"><a href="login.html" target="main">LOGIN</a></td>
<td width="200"><a href="registrationpage.html" target="main">REGISTRATION</a></td>
<td width="200"><a href="catalog.html" target="main">CATALOGUE</a></td>
<td width="200"><a href="cart page.html" target="main">CART</a></td>
</tr>
</table>
</body>
</html>
Output:-

Srinivasa Institute of Engg. & Tech. 41


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

database.php
<?php
$c=mysql_connect("localhost","root"
,""); $d=mysql_select_db("hari",$c);
if($c)
echo"connected to database
<br>"; else
echo"not
connected"; ?>

Srinivasa Institute of Engg. & Tech. 42


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

sqlcreatetab1.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("yesu", $con);
// Create table
mysql_select_db("yesu", $con);
$sql = "CREATE TABLE cart(Title varchar(15),Author varchar(15),Price varchar(15),
Quantity varchar(15))";
// Execute query
mysql_query($sql,$con);
echo "Table created" . mysql_error();
mysql_close($con);
?>

Output:-

cart.php
<?php
session_sta
rt();
$_SESSION['a1']=$_POST['bname';
$_SESSION['b1']=$_POST['price'];

Srinivasa Institute of Engg. & Tech. 43


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

$_SESSION['c1']=$_POST['quantiy'];
$_SESSION['d1']=$_POST['amount];
?>
<html>
<title>cart page</title>
<body><center>
<table width="100%" border="2">
<tr>
<th>book name</th>
<th>price</th><th>quantity</th><th>amount</th>
</tr>
<tr>
<td align="center">xml bible</td> <td
align="center">$40.5</td> <td align="center">01</td>
<td
align="center">$40.5</td
> </tr>
<tr>
<td
align="center">java</td>
<td
align="center">$100</td
> <td
align="center">03</td>
<td
align="center">$300</td
> </tr>
<tr>
<td
align="center">wt</td>
<td
align="center">$500</td
>
<td align="center">05</td>
<td align="center">$2500</td> </tr>
<tr>
<tdalign="center">
<?php
echo $_SESSION['a1'];
?></td>
<tdalign="center">
<?php echo $_SESSION['b1']; ?>
</td> <td align="center">
<?php echo $_SESSION['c1']; ?>
</td> <td align="center">

Srinivasa Institute of Engg. & Tech. 44


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

<?php
echo $_SESSION['d1']; ?></td> </tr>
</table>
</center>
<form action="db.php">
<input type="submit" value="insert into
db"/> </form>
<form action="logout.php">
<input type="submit" Value="logout"/> </form>
</body>
</html>

test.php

<?php
$y=mysql_connect("localhost","root","");
mysql_select_db("yesu",$y);
$x="select * from cart";
$res=mysql_query($x);
$var="AddtoCart";

echo "<form method=post action=cart.php>";


echo "<center><h1>Following Books are Available</h1></center>";
$num=1;

Srinivasa Institute of Engg. & Tech. 45


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

echo "<center><table
border=1>"."<tr>"."<th>"."Title"."</th>"."<th>"."Author"."</th>"."<th>"."Price"."</th>"."<th>"."Q
uantity"."</th>"."<th>"."Cart"."</th>"."</tr></center>";
while($val=mysql_fetch_array($res))
{
$str= "btn"+ $num;
echo
"<tr>"."<td>".$val['Title']."</td>"."<td>".$val['Author']."</td>"."<td>".$val['Price']."</td>"."<td>".$
val['Quantity']."</td>"."<td>"."<input
type=button name=$str value=$var>"."</input>"."</td>"."</tr>";
$num++;
}
echo "</form>";

?>

Output:-

Cart1.php

<html>
<body>
<?php
echo " <b><h1><center>U r Cart is Empty</center></h1>";
echo "<center><table >"."
<tr>"."<th>"."Title"."</th>"."<th>"."Author"."</th>"."<th>"."Price"."</th>"."<th>"."Quantity"."</th
>"."</tr></center>";
echo "<br>";
//echo " <tr>"."<td>"."Total Amount "."</td>"."<td>"."Rs.0"."</td>"."</tr></center>";

Srinivasa Institute of Engg. & Tech. 46


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

echo " <tr>"."<td colspan=4>"."Total Amount Rs.0"."</td>"."</tr></center>";

?>
</body>
</html>

db.php
<?php
session_sta
rt();
include("database.php");
$a2=$_SESSION['a1'];
$b2=$_SESSION['b1'];
$c2=$_SESSION['c1'];
$d2=$_SESSION['d1']; //echo $a2;
/*
$x="create table cart1(bname varchar(10) notnull,price varchar(10) notnull,quantity varchar(10)
not null, amount varchar(10) notnull)"; $y=mysql_query($x);
if($x)
echo"<br> created"; else
echo"<br>not created"; */
$query="insert into cart values($a2,$b2,$c2,$d2)";
$q=mysql_query($query);

Srinivasa Institute of Engg. & Tech. 47


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

if($q)
echo"<br> inserted successfully"; else
echo"<br><br> not inserted";
session_unset();
?>
goto_catalogue.php

<?php
echo"<br><br><br>";
?>
<html>
<body allign="centre">
<form action="cart.php" method="post">
<fieldset>
<legend>to catalog page</legend>
book_name::<input type="text" name="bname"/><br><br>
price ::<input type="text" name="price"/><br><br>
quantity::<input type="text" name="quantity"/><br><br>
amount::<input type="text" name="amount"/><br><br> <input
type="submit" value="submit"/>
<input type="reset" value="reset"/>
</fieldset>
</form>
</body>
</html>

login.php
<?php
echo"hai this is login page"; ?>
<html>
<form action="usercheck.php" method="post">
<fieldset>
<legend>LOG IN PAGE</legend>
username::<input type="text" name="uname"/><br><br>
password::<input type="password" name="pwd"/><br><br>
<input type="submit" value="login"/>
<input type="reset" value="reset"/><br><br>
</fieldset>
</form>
</html>
loginout.php
<?php
echo "logout successfully";

Srinivasa Institute of Engg. & Tech. 48


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

session_unset();
?>
usercheck.php
<?php
include("database.php"); $r="select *
from users"; $t=mysql_query($r);
while($u=mysql_fetch_array($t))
{
extract($u);
$x=$uname;
$y=$password;
if($_POST['uname']==$x && $_POST['pwd']==$y)
{
echo"valid user";
include("uservalid.php");
}
else
echo"not a valid user";
}
?>

uservalid.php

<?php
?>
<form action="goto_catalogue.php">
<input type="submit" value="GOTOCATA"/>
</form>
Output:

Srinivasa Institute of Engg. & Tech. 49


Department of CSE Web Technologies Lab

Regd.No: Sheet No:

Result:-

Srinivasa Institute of Engg. & Tech. 50

You might also like