You are on page 1of 34

Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

ASSIGNMENT:-

1. Create a web page using PHP which accept item information like item name, item type, and quantity from the
customer which gives the facility of placing the order. Also give facility of displaying order according to order no.

<?php
include("connection.php");

if(isset($_REQUEST['o_id']))
{
$oid = $_REQUEST['o_id'];
$res = mysql_query( $query);
$ans = mysql_fetch_array($res);

$query = "INSERT INTO order ('item_id') VALUES ($oid)";

$cnt = mysql_query($query);

if($cnt> 0)
{
header("Location:pro1.php?msg=order successfully recorded....");
}
else
{
header("Location:pro1.php?msg=order not recorded...." );
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Order And Item details </title>
</head>
<body>
<h2> Items Details </h2>
<table border = "2" cellpadding = "2">
<tr>
<th> Name </th>
<th> Type </th>
<th> Quantity </th>
<th> Order </th>
</tr>
<?php
$query = "select * from item";
$res = mysql_query($query);
$cnt = mysql_num_rows($res);
if ($cnt> 0)

{
1
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102
while ($ans = mysql_fetch_array($res))

{
$type = $ans['type'];
$qty = $ans['qun'];
$name = $ans['name'];
$id = $ans['i_id'];
echo "<tr>";
echo "<td> $name </td>";
echo "<td> $type </td>";
echo "<td> $qty</td>";
echo "<td><a href=\"pro1.php?o_id=$id\"> Order Now </a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan = \"4\" align = \"center\" > Records Not Found......... </td></tr>";
}
?>
</table>
<br><br>
<h2> Total order </h2>
<table border = "2" cellpadding = "2">
<tr>
<th> Name </th>
<th> Type </th>
<th>Order_time</th>
</tr>
<?php
$query = "select * from `order` o, `item` i where o.item_id = i.i_id";
$res = mysql_query($query);
$cnt = mysql_num_rows($res);
if ($cnt> 0)
{
while ($ans = mysql_fetch_array($res))
{
$type = $ans['type'];
$name = $ans['name'];
$time = $ans['o_time'];
echo "<tr>";
echo "<td> $name </td>";
echo "<td> $type </td>";
echo "<td> $time </td>";
echo "</tr>";
}
}

else
{
2
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102
echo "<tr><td colspan = \"3\" align = \"center\" > Records Not Found......... </td></tr>";

}
?>
</table>
</body>
</html>

Output:-

2. Create a web page using PHP which accept ticket booking information like client_name, source, destination,
address, nos. Of passenger travelling, travelling date and train number. Store these records using mySQL database.
Provide insert and navigation options.

<?php
include("connection.php");

if(isset($_REQUEST['msg']))

{
$msg =$_REQUEST['msg'];

3
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102
if($msg == "Ticket Booking")

{
echo "<font color = \"green\"> Ticket Booking...... </font><br>";
}
else
{
echo "<font color = \"red\"> Ticket not Booking......... </font><br>";
}
}
if(isset($_REQUEST['submit']))
{
$clientname = $_REQUEST['cname'];
$source = $_REQUEST['source'];
$destination = $_REQUEST['destination'];
$address = $_REQUEST['address'];
$noofpass = $_REQUEST['noofpass'];
$tdate = $_REQUEST['tdate'];
$trainnum = $_REQUEST['trainnum'];
$query = "INSERT INTO ticket_book (client_name , source , destination , address , noofpass, tdate ,
train_num) VALUES ('$clientname', '$source' , '$destination' , '$address' , '$noofpass' , '$tdate' , '$trainnum')";
$cnt = mysql_query($query);

if($cnt> 0)
{
header("Location:pro2-1.php?msg=Ticket Booking");
}
else
{
header("Location:pro2-1.php?msg=Ticket not Booking" );
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Ticket booking </title>
</head>
<body>

<ul>
<li><a href = "pro2-1.php"> Ticket Booking Form </a></li>
<li><a href = "pro2-2.php"> Tickets Details </a></li>
</ul>
<h2> Ticket Booking </h2>
<form name = "f2" action = "" method = "post">

Client Name : <input type = "text" name = "cname"><br><br>


Source : <input type = "text" name = "source"><br><br>
Destination : <input type = "text" name = "destination"><br><br>
4
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102
Address : <textarea name = "address"></textarea><br><br>

NoOfPass : <input type = "text" name = "noofpass"><br><br>


Ticket Date : <input type = "date" name = "tdate" ><br><br>
Train Number : <input type = "text" name = "trainnum"><br><br><br>

<input type = "Submit" name = "submit" value = "Booking"><br>


</form>
</body>
</html>

Booking detail :-
<?php
include("connection.php");
?>
<html>
<head>
<title> Ticket details </title>
</head>
<body>
<ul>
<li><a href = "pro2-1.php"> Ticket Booking Form </a></li>
<li><a href = "pro2-2.php">TIckets Details </a></li>
</ul>

<h2> Ticket Details </h2>


<table border = "2" cellpadding = "2">
<tr>
<th> Name </th>
<th> Train-Number </th>
<th> Travelling-Date </th>
<th> Source-Destination </th>
</tr>
<?php
$query = "select * from ticket_book";
$res = mysql_query( $query);
$cnt = mysql_num_rows($res);
if ($cnt> 0)
{
while ($ans = mysql_fetch_array($res))
{
$tno = $ans['train_num'];
$name = $ans['client_name'];
$tdate = $ans['tdate'];
$source = $ans['source'];

$destination = $ans['destination'];
echo "<tr>";
echo "<td> $name </td>";
echo "<td> $tno</td>";
5
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102
echo "<td> $tdate</td>";

echo "<td> $source-$destination </td>";


}
}
else
{
echo "<tr><td colspan = \"4\" align = \"center\" > Records Not Found......... </td></tr>";
}
?>
</table>
</body>
</html>

Output:-

3. Create a web page using PHP which accepts student information like roll no, name, age, city and phone_number.
Store these records in mySQL database. Provide insert, update by roll no. & view options.

6
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<?php
include("connection.php");
if(isset($_REQUEST['btn']))
{
$Rollno=$_REQUEST['txtroll'];
$name=$_REQUEST['txtName'];
$gender=$_REQUEST['gender'];
$Age=$_REQUEST['txtage'];
$city=$_REQUEST['cmbcity'];
$phone=$_REQUEST['txtphone'];
$query="inser into
student(Roll_no,name,gender,age,city,phone)values('$Rollno','$name','$gender','$Age','$city','$phone')";
$cnt=mysql_query($query);
if ($cnt==1)
{
header("Location:p2.php?msg=ok");
}
else
{
header("Location:p2.php?msg=notok");
}
}
if(isset($_REQUEST['updbtn']))
{
//$id=$_REQUEST['editid'];
$Rollno=$_REQUEST['txtroll'];
$name=$_REQUEST['txtName'];
$gender=$_REQUEST['gender'];
$Age=$_REQUEST['txtage'];
$city=$_REQUEST['cmbcity'];
$phone=$_REQUEST['txtphone'];
$query="update student set name='$name',gender='$gender',age='$Age',city='$city',phone='$phone' where
Roll_no=$Rollno";
//echo $query;
$cnt=mysql_query($query);
if($cnt>0)
{
header("location:p2.php?edit=ok");
}
else
{
header("location:p2.php?edit=not ok");
}

}
?>

<html>
<head>
7
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<title>form</title>
</head>
<body>
<h1>Registration</h1>
<?php

if(isset($_REQUEST['editid']))
{
$editid=$_REQUEST['editid'];
$query="select * from student where Roll_no=$editid";
$res=mysql_query($query);
$ans=mysql_fetch_array($res);
$txtroll=$ans['Roll_no'];
$txtName=$ans['name'];
$gender=$ans['gender'];
$txtage=$ans['age'];
$cmbcity=$ans['city'];
$txtphone=$ans['phone'];

}
else
{
$txtroll="";
$txtName="";
$gender="";
$txtage="";
$cmbcity="";
$txtphone="";
}
?>
<?php
if(isset($_REQUEST['msg']))
{
$msg=$_REQUEST['msg'];
if($msg=="ok")
{
echo "<font color=\"green\">Record insert..........</font><br>";
}
else
{
echo "<font color=\"red\">Record not insert..............</font><br>";
}

}
?>
<?php
if(isset($_REQUEST['edit']))
{
$msg=$_REQUEST['edit'];
8
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

if($msg=="ok")
{
echo "<font color=\"green\">Record Update..........</font><br>";
}
else
{
echo "<font color=\"red\">Record not Uadate..............</font><br>";
}
}
?>
<form name="frm" method="post" action="">
Rollno:<input type="text" name="txtroll" value="<?php echo $txtroll ?>"><br/><br/>
student_name:<input type="text" name="txtName" value="<?php echo $txtName ?>"><br/><br/>
Gender: Male<input type="radio" name="gender" value="Male" checked="checked">
Female<input type="radio" name="gender" value="Female"><br/><br/>
Age:<input type="text" name="txtage" value="<?php echo $txtage ?>"><br/><br/>
City:<select name="cmbcity" value="<?php echo $cmbCity ?>">
<option>Select City</option>
<option>Surat</option>
<option>Rajkot</option>
<option>Ahemdabad</option>
</select><br/><br/>
Phone:<input type="text" name="txtphone" value="<?php echo $txtphone ?>"><br/><br/>
<?php
if (isset($_REQUEST['editid']))
{
?>
<input type="submit" name="updbtn" value="Update"/><br><br>
<?php
}
else
{
?>
<input type="submit" name="btn" value="Insert"/><br><br>
<?php
}
?>
</form>
<table align="center" border="2">
<tr>
<th>Rollno</th>

<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>city</th>
<th>phone</th>
</tr>
<?php
9
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

include("connection.php");
$query="select * from student";
$res=mysql_query($query);
$cnt=mysql_num_rows($res);
if($cnt>0)
{
$i=1;
while($ans=mysql_fetch_array($res))
{
$Rollno=$ans['Roll_no'];
$name=$ans['name'];
$gender=$ans['gender'];
$age=$ans['age'];
$city=$ans['city'];
$phone=$ans['phone'];
echo "<tr>";
echo "<td>".$Rollno."</td>";
echo "<td>".$name."</td>";
echo "<td>".$gender."</td>";
echo "<td>".$age."</td>";
echo "<td>".$city."</td>";
echo "<td>".$phone."</td>";
echo"<td><a href=\"p2.php?editid=$Rollno\">Update</a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"10\"><center>Record not found</center></td></tr>";
}
?>
</table>
</body>
</html>

Output:-

10
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

4. Create web pages which accept book details like book_code, book_name, author_name, cost, ISBN_No. Create
database and provide facility to updating book by book_code and searching by book_name and author_name.

<?php
include("connection.php");
if(isset($_REQUEST['editid']))
{
$editid=$_REQUEST['editid'];
$query="select * from books where book_code=$editid";
$res=mysql_query($query);
$ans=mysql_fetch_array($res);
$book_code = $ans['book_code'];
$book_name = $ans['book_name'];
$author_name = $ans['author_name'];
$cost = $ans['cost'];
$isbn = $ans['isbn'];

}
else
{
$book_code = "";
$book_name = "";

$author_name = "";
$cost = "";
11
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

$isbn = "";

}
// This condition for insert record
if (isset($_REQUEST['btnInsert']))
{
$book_code = $_REQUEST['book_code'];
$book_name = $_REQUEST['book_name'];
$author_name = $_REQUEST['author_name'];
$cost = $_REQUEST['cost'];
$isbn = $_REQUEST['isbn'];
$query = "INSERT INTO `books`(`book_code`, `book_name`, `author_name`, `cost`, `isbn`) VALUES
($book_code,'$book_name','$author_name',$cost,$isbn)";
$cnt = mysql_query($query);
if ($cnt> 0)
{
header("Location:p4.php?msg=inserted");
else
header("Location:p4.php?msg=notinserted");
}
// This condition for update record
if (isset($_REQUEST['btnUpdate']))
{
$book_code = $_REQUEST['book_code'];
$book_name = $_REQUEST['book_name'];
$author_name = $_REQUEST['author_name'];
$cost = $_REQUEST['cost'];
$isbn = $_REQUEST['isbn'];
$query = "update books set
book_name='$book_name',author_name='$author_name',cost='$cost',isbn='$isbn' where book_code=$book_code";
//echo $query;
$cnt = mysql_query($query);
if ($cnt> 0)
{
header("Location:p4.php?edit=ok");
}
else
{
header("Location:p4.php?edit=notok");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Document</title>

</head>
<body>
<h1>BOOK INFORMATION</h1>
12
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<form name="frm" method="post" action="">


Book Code: <input type="text" name="book_code" value="<?php echo $book_code ?>"><br>
Book Name: <input type="text" name="book_name" value="<?php echo $book_name ?>"><br>
Author Name: <input type="text" name="author_name" value="<?php echo $author_name ?>"><br>
Cost: <input type="text" name="cost" value="<?php echo $cost ?>"><br>
ISBN: <input type="text" name="isbn" value="<?php echo $isbn ?>"><br>
<br>
<?php
if (isset($_REQUEST['editid']))
{
?>
<input type="submit" name="btnUpdate" value="Update" />
<?php
}
else
{
?>
<input type="submit" name="btnInsert" value="Insert" />
<?php
}
?>
</form>
<table border="2">
<tr>
<th>Book Code</th>
<th>Book Name</th>
<th>Author Name</th>
<th>Cost</th>
<th>ISBN</th>
<th>Update</th>
</tr>
<?php
include("connection.php");
$query="select * from books";
$res=mysql_query($query);
$cnt=mysql_num_rows($res);
if($cnt>0)
{
$i=1;
while($ans=mysql_fetch_array($res))
{
$book_code=$ans['book_code'];
$book_name=$ans['book_name'];
$author_name=$ans['author_name'];

$cost=$ans['cost'];
$isbn=$ans['isbn'];
echo "<tr>";
echo "<td>".$book_code."</td>";
13
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

echo "<td>".$book_name."</td>";
echo "<td>".$author_name."</td>";
echo "<td>".$cost."</td>";
echo "<td>".$isbn."</td>";
echo "<td><a href=\"p4.php?editid=$book_code\">Update</a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"10\"><center>Record not found</center></td></tr>";
}
?>
</table><br><br>
<form name="frm" method="post" action="">
<input type="text" name="search" id="">
<input type="submit" name="btnSearch" value="Search" />
</form>
<table border="2">
<tr>
<th>Book Code</th>
<th>Book Name</th>
<th>Author Name</th>
<th>Cost</th>
<th>ISBN</th>
<th>Update</th>
</tr>
<?php
if (isset($_REQUEST['btnSearch']))
{
$name = $_REQUEST['search'];
$query = "select * from books where book_code= $name";
$res=mysql_query($query);
$cnt=mysql_num_rows($res);
if ($cnt> 0)
{
while($ans=mysql_fetch_array($res))
{
$book_code=$ans['book_code'];
$book_name=$ans['book_name'];
$author_name=$ans['author_name'];
$cost=$ans['cost'];
$isbn=$ans['isbn'];

echo "<tr>";
echo "<td>".$book_code."</td>";
echo "<td>".$book_name."</td>";
echo "<td>".$author_name."</td>";
echo "<td>".$cost."</td>";
14
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

echo "<td>".$isbn."</td>";
echo "<td><a href=\"p4.php?editid=$book_code\">Update</a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"6\" align=\"center\">Records Not Found.....</td></tr>";
}
}
?>
</table>
</body>
</html>

Output:-

5. Create a website for online mobile shopping of different companies. This website displays different mobiles with
their prices. (Company, Model Name, price, etc.) Admin can add or remove mobiles. Customer can search mobile
according to price. Also provide proper validations.

15
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<?php
include("connection.php");
if(isset($_REQUEST['btn']))
{
$company=$_REQUEST['company'];
$mname=$_REQUEST['mname'];
$price=$_REQUEST['price'];
$ram=$_REQUEST['ram'];
$query="insert into mobile(company,mname,price,ram)values('$company','$mname','$price','$ram')";
$cnt=mysql_query($query);
if ($cnt==1)
{
header("Location:p5.php?msg=ok");
}
else
{
header("Location:p5.php?msg=notok");
}
}
if(isset($_REQUEST['delid']))
{
$id=$_REQUEST['delid'];
$query="delete from mobile where company=$company";
mysql_query($query);
header("Location:p5.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>q5</title>
</head>
<body>
<h1>online mobile shopping</h1>
<form action="" method="POST" name="addForm">
Company: <input type="text" name="company" required pattern="^[a-z0-9]*$"><br>
Model name: <input type="text" name="mname" required pattern="^[a-zA-Z]*$"><br>
Price: <input type="text" name="price" required pattern="^[0-9]*$"><br>
Ram: <input type="text" name="ram" required pattern="^[0-9]*$"><br>
<br>
<input type="submit" name="btnInsert" value="Insert" />
</form>

<br><br>
<table border="2">
<tr>
<th>Company</th>
<th>Model name</th>
<th>Price</th>
16
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<th>Ram</th>
<th>Delete</th>
</tr>
<?php
$query = "select * from mobile";
$res=mysql_query($query);
$cnt=mysql_num_rows($res);
if ($cnt> 0)
{
while($ans=mysql_fetch_array($res))
{
$company=$ans['company'];
$mname=$ans['mname'];
$price=$ans['price'];
$ram=$ans['ram'];
echo "<tr>";
echo "<td>".$company."</td>";
echo "<td>".$mname."</td>";
echo "<td>".$price."</td>";
echo "<td>".$ram."</td>";
echo "<td><a href=\"p5.php?delid=$company\">Delete</a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"5\" align=\"center\">Records Not Found.....</td></tr>";
}
?>
</table><br><br>
<form name="frm" method="post" action="">
<input type="text" name="search" id="">
<input type="submit" name="btnSearch" value="Search" />
</form>
<table border="2">
<tr>
<th>Company</th>
<th>Model Name</th>
<th>Price</th>
<th>Ram</th>
<th>Delete</th>

</tr>
<?php
if (isset($_REQUEST['btnSearch']))
{
$price = $_REQUEST['search'];
$query = "select * from mobile where price like '$price%'";
$res=mysql_query($query);
17
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

$cnt=mysql_num_rows($res);
if ($cnt> 0)
{
while($ans=mysql_fetch_array($res))
{
$company=$ans['company'];
$mname=$ans['mname'];
$price=$ans['price'];
$ram=$ans['ram'];
echo "<tr>";
echo "<td>".$company."</td>";
echo "<td>".$mname."</td>";
echo "<td>".$price."</td>";
echo "<td>".$ram."</td>";
echo "<td><a href=\"p5.php?delid=$company\">Delete</a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"5\" align=\"center\">Records Not Found.....</td></tr>";
}
}
?>
</table>
</body>
</html>

Output:-

18
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

6. Create a web page for AMAZON that gives order details and status of order according to the order no. given by
customer. Give appropriate validations. Also give facility for viewing past orders by date. (Tables : cust_mast,
item_mast, order_mast, order_detail)

<?php
include("connection.php");
?>
<html>
<head>
<title> Amazon Website </title>
</head>
<body>
<h2><center> Amazon </center></h2>
<h4> Order Details </h4>
<form name = "f1" action = "" method = "post" >
<input type = "text" name ="search" required pattern = "^[0-9]*$">
<input type = "submit" name = "submit" value = "Click to order">
</form>
<br><br>
<table border = "2" cellpadding = "2">
<tr>
<th> Order No </th>
<th> Product Name </th>
<th> Product type </th>
<th> Product Price </th>
<th> Order status </th>
</tr>
<?php
if(isset($_REQUEST['submit']))
{
$ono =$_REQUEST['search'];

$query = "select * from order_mast o, order_details d, item_mast i where d.o_id = o.id and o.id = i.id and d.o_id =
$ono ";
$res = mysql_query( $query);
$cnt = mysql_num_rows($res);
if ($cnt> 0)
{
while ($ans = mysql_fetch_array($res))
{
$oid = $ans['o_id'];
$name = $ans['name'];
$type = $ans['type'];
$price = $ans['price'];
$status = $ans['status'];
if($status == "ofd")
{
$color = "green";

19
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

}
else
{
$color = "red";
}
echo "<tr>";
echo "<td> $oid</td>";
echo "<td> $name </td>";
echo "<td> $type </td>";
echo "<td> $price </td>";
echo "<td style = 'color: $color;'> $status </td>";
echo "</tr>";
}
}
}
else
{
echo "<tr><td colspan = \"5\" align = \"center\" > Records Not Found......... </td></tr>";
}
?>
</table>
<br><br>
<h4> Facility Details </h4>
<form name = "f2" action = "" method = "get" >
<input type = "date" name ="searchdt" required >
<input type = "submit" name = "submitdt" value = "Click to order">
</form>
<table border = "2" cellpadding = "2">
<tr>
<th> Order No </th>
<th> Product Name </th>

<th> Product type </th>


<th> Product Price </th>
<th> Order status </th>
</tr>
<?php
if(isset($_REQUEST['submitdt']))
{
$dt =$_REQUEST['searchdt'];
$query = "select * from order_mast o, order_details d, item_mast i where d.o_id = o.id and o.i_id = i.id and
o.time = '$dt'";
$res = mysql_query($query );
$cnt = mysql_num_rows($res);
if ($cnt> 0)
{
while ($ans = mysql_fetch_array($res))
{
$oid = $ans['o_id'];
20
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

$name = $ans['name'];
$type = $ans['type'];
$price = $ans['price'];
$status = $ans['status'];
if($status == "ofd")
{
$color = "green";
}
else
{
$color = "red";
}
echo "<tr>";
echo "<td> $oid</td>";
echo "<td> $name </td>";
echo "<td> $type </td>";
echo "<td> $price </td>";
echo "<td style = 'color: $color;'> $status </td>";
echo "</tr>";
}
}
}
else
{
echo "<tr><td colspan = \"5\" align = \"center\" > Records Not Found......... </td></tr>";
}
?>
</table>
</body>
</html>

Output:-

Order_details:-

Item_must:-

21
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

Order_mast:-

Cust_mast:-

22
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

7. Create a registration page for matrimony website with all required validations. Fields are like person_name, city,
mobno, cast, subcast, gender, qualification, etc. Also give facility of searching records by city and cast. Use concept of
session.

<?php
session_start();
include('connection.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<h1>Matrimony</h1>
<a href="qr7.php">Registration</a>&nbsp;&nbsp;
<a href="qh7.php">Home</a><br><br>
<?php
if(!isset($_SESSION['username']))
{
echo 'Welcome Guest.';
}
else
{
echo 'Welcome ' . $_SESSION['username'];
}
?>
<form action="" method="get">
<label>
<h3>Enter The City or Cast</h3>
</label>
<input type="text" name="search" id="">
<input type="submit" name="btnSearch" value="Search" />
</form><br><br>

<table border="2">
<tr>
<th>Name</th>
<th>City</th>
<th>Phone</th>
<th>Cast</th>
<th>Subcast</th>
<th>Gender</th>
<th>Qualification</th>
<th>Date of Birth</th>
</tr>
<?php
23
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

if (isset($_REQUEST['btnSearch']))
{
$name = $_REQUEST['search'];
$query="select * from reg where city='$name' or cast='$name'";
$res = mysql_query($query);
$cnt = mysql_num_rows($res);
if ($cnt> 0)
{
while ($ans = mysql_fetch_array($res))
{
$name = $ans['name'];
$city = $ans['city'];
$phone = $ans['phone'];
$cast = $ans['cast'];
$subcast = $ans['subcast'];
$gender = $ans['gender'];
$qualification = $ans['qualification'];
$dob = $ans['dob'];
echo "<tr>";
echo "<td>$name</td>";
echo "<td>$city</td>";
echo "<td>$phone</td>";
echo "<td>$cast</td>";
echo "<td>$subcast</td>";
echo "<td>$gender</td>";
echo "<td>$qualification</td>";
echo "<td>$dob</td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"8\" align=\"center\">Records Not Found.....</td></tr>";
}
}

?>
</body>
</html>
Registration page:
<?php
session_start();
include("connection.php");
if (isset($_REQUEST['btnInsert']))
{
$name = $_REQUEST['name'];
$city = $_REQUEST['city'];
$phone = $_REQUEST['phone'];
$cast = $_REQUEST['cast'];
24
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

$subcast = $_REQUEST['subcast'];
$gender = $_REQUEST['gender'];
$qualification = $_REQUEST['qualification'];
$dob = $_REQUEST['dob'];
$query="insert into
reg(name,city,gender,phone,cast,subcast,dob,qualification)values('$name','$city','$gender','$phone','$cast','$subcast','$dob','$q
ualification')";
$cnt=mysql_query($query);
$_SESSION['username'] = $name;
if ($cnt> 0)
{
header("Location:qh7.php?msg=ok");
}
else
{
header("Location:qh7.php?msg=notok");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<h1>Matrimony</h1>
<a href="qr7.php">Registration</a>&nbsp;&nbsp;
<a href="qh7.php">Home</a><br><br>
<form action="" method="POST">
<table>
<tr>
<td>
<label>Name:</label>
</td>

<td>
<input type="text" name="name" required pattern="^[a-zA-Z]*$">
</td>
</tr>
<tr>
<td>
<label>City:</label>
</td>
<td>
<input type="text" name="city" required pattern="^[a-zA-Z]*$">
</td>
</tr>
<tr>
<td>
25
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<label>Genber:</label>
</td>
<td>
Male<input type="radio" name="gender" value="Mele" checked="checked">
Female<input type="radio" name="gender" value="Female">
</td>
</tr>
<tr>
<td>
<label>Phone:</label>
</td>
<td>
<input type="text" name="phone" required pattern="^[0-9]{10}$">
</td>
</tr>
<tr>
<td>
<label>Cast:</label>
</td>
<td>
<input type="text" name="cast" required pattern="^[a-zA-Z]*$">
</td>
</tr>
<tr>
<td>
<label>Subcast:</label>
</td>
<td>
<input type="text" name="subcast" required pattern="^[a-zA-Z]*$">
</td>
</tr>
<tr>
<td>

<label>Date of Birth:</label>
</td>
<td>
<input type="date" name="dob" required >
</td>
</tr>
<tr>
<td>
<label>Qualification: </label>
</td>
<td>
<input type="text" name="qualification" required pattern="^[0-9a-zA-Z]*$">
</td>
</tr>
<tr>
26
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<td><input type="submit" name="btnInsert" value="Register" /></td>


</tr>
</table>
</form>
</body>
</html>

Output:-

27
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

8. Create a website for particular hotel. Customer can book rooms using this website and also view status of available
rooms. Admin can add room detail in this website. (Tables: Room_Mast, Booking, Cust_Mast)

<?php
include("connection.php");

if(isset($_REQUEST['msg']))
{
$msg =$_REQUEST['msg'];
if($msg == "ok")
{
echo "<font color = \"green\"> Record Inserted / Updated successfully...... </font> <br>";
}
else
{
echo "<font color = \"red\"> Record Not Inserted / Updated......</font> <br>";
}
}
if (isset($_REQUEST['editid']))
{
$editid = $_REQUEST['editid'];
$query = "select * from room_master where id=$editid";
$res = mysql_query($query);
$ans = mysql_fetch_array($res);
$name = $ans['name'];
$cost = $ans['cost'];
$status = $ans['status'];
$id = $ans['id'];
$type = $ans['type'];
}
else

{
$name = "";
$cost = "";
$status = "";
$id = "";
$type = "";
}
// This condition for insert record
if (isset($_REQUEST['btnInsert']))
{
$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$type = $_REQUEST['type'];
$cost= $_REQUEST['cost'];
$status = $_REQUEST['status'];
$query="insert into room_master(id,name,type,cost,status)values('$id','$name','$type','$cost','$status')";
$cnt=mysql_query($query);

28
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

if ($cnt>0)
{
header("Location:pro8-1.php?msg=ok");
}
else
{
header("Location:pro8-1.php?msg=notok");
}
}

// This condition for update record


if (isset($_REQUEST['btnUpdate']))
{

$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$cost = $_REQUEST['cost'];
$type = $_REQUEST['type'];
$status = $_REQUEST['status'];
$query = "update room_master set name='$name',type='$type',cost='$cost',status='$status' where id=$id";
//echo $query;
$cnt=mysql_query($query);
if($cnt>0)
{
header("location:pro8-1.php?edit=ok");
}
else
{
header("location:pro8-1.php?edit=not ok");
}

}
?>
<html>
<head>
<title> Booking room </title>
</head>
<body>
<h1> Room Booking </h1>
<a href="pro8-1.php"> admin </a>&nbsp;&nbsp;
<a href="pro8-2.php"> customer </a><br><br>

<form name="frm" method="post" action="">

Room no:<input type="text" name="id" value="<?php echo $id ?>"/><br><br>


Room Name:<input type="text" name="name"value="<?php echo $name ?>"><br/><br/>
Room Types:<input type="text" name="type" value="<?php echo $type ?>"/><br/><br/>
Cost:<input type="text" name="cost" value="<?php echo $cost ?>"/><br/><br/>
status:<input type="text" name="status" value="<?php echo $status ?>"/><br/><br/>
29
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

<?php
if (isset($_REQUEST['editid']))
{
?>
<input type="submit" name="btnUpdate" value="Update" />
<?php
}
else
{
?>
<input type="submit" name="btnInsert" value="Insert" />
<?php
}
?>

</form>
<table border="2" cellpadding = "2">
<tr>
<th>Room No.</th>
<th>Name</th>
<th>Room Type</th>
<th>Cost</th>
<th>Status</th>
<th>Update</th>

</tr>
<?php
include("connection.php");

$query="select * from room_master";


$res=mysql_query($query);
$cnt=mysql_num_rows($res);
if($cnt>0)
{
$i=1;
while($ans=mysql_fetch_array($res))
{
$id=$ans['id'];
$name=$ans['name'];
$type=$ans['type'];
$cost=$ans['cost'];
$status=$ans['status'];

echo "<tr>";
echo "<td>".$id."</td>";
echo "<td>".$name."</td>";
echo "<td>".$type."</td>";
echo "<td>".$cost."</td>";
echo "<td>".$status."</td>";
30
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

echo "<td><a href=\"pro8-1.php?editid=$id\">Update</a></td>";


echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"5\"><center>Record not found</center></td></tr>";
}
?>
</table>
</body>
</html>

Customer page :-
<?php
include("connection.php");
if (isset($_REQUEST['bid']))
{
$editid = $_REQUEST['bid'];
$query = "select * from room_master where id=$editid";
$res = mysql_query($query);
$ans = mysql_fetch_array($res);
$name = $ans['name'];
$cost = $ans['cost'];
$status = $ans['status'];
$id = $ans['id'];
$type = $ans['type'];

}
else
{
$name = "";
$cost = "";
$status = "";
$id = "";
$type = "";
}
// This condition for insert record
if (isset($_REQUEST['btnInsert']))
{
$id = $_REQUEST['id'];
$phone = $_REQUEST['phone'];

$query1 = "select * from cust_mast where phone = $phone";


echo $query1;
$res = mysql_query($query1);
$cnt = mysql_num_rows($res);

$cid = $ans['id'];
31
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

$query = "insert into booking ('r_id', 'c_id') values ('$id', '$cid')";


$cnt = mysql_query($query);
if ($cnt>0)
{
header("Location:pro8-2.php?msg=Inserted");
}
else
{
header("Location:pro8-2.php?msg=notInserted");
}
}
?>
<html>
<head>
<title> Customer Page </title>
</head>
<body>
<h1> Room Booking </h1>
<a href="pro8-1.php"> admin </a>&nbsp;&nbsp;
<a href="pro8-2.php"> customer </a><br><br>

<form name="frm" method="post" action="">

Room no : <input type="text" name="id" value="<?php echo $id ?>"/><br><br>


Room Name : <input type="text" name="name"value="<?php echo $name ?>"><br/><br/>

Room Types : <input type="text" name="type" value="<?php echo $type ?>"/><br/><br/>


Cost : <input type="text" name="cost" value="<?php echo $cost ?>"/><br/><br/>
Status : <input type="text" name="status" value="<?php echo $status ?>"/><br/><br/>
Enter Your Phone no : <input type="text" name="phone" value=""/><br/><br/>

<?php
if(isset($_REQUEST['bid']))
{
?>
<input type="submit" name="btnInsert" value=" Confirm room" />
<?php
}
?>
</form>

<table border="2" cellpadding = "2">


<tr>
<th>Room No.</th>
<th>Name</th>
<th>Room Type</th>
<th>Cost</th>
<th>Status</th>
<th>Update</th>
32
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

</tr>
<?php
include("connection.php");
$query="select * from room_master";
$res=mysql_query($query);
$cnt=mysql_num_rows($res);

if($cnt>0)
{
$i=1;
while($ans=mysql_fetch_array($res))
{
$id=$ans['id'];
$name=$ans['name'];
$type=$ans['type'];
$cost=$ans['cost'];
$status=$ans['status'];

if($status == "available")
$link = "pro8-2.php?bid=$id";
else
$link = "javascript:void(0);";

echo "<tr>";

echo "<td>".$id."</td>";
echo "<td>".$name."</td>";
echo "<td>".$type."</td>";
echo "<td>".$cost."</td>";
echo "<td>".$status."</td>";
echo "<td><a href=\"$link\"> Booking Room </a></td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"5\"><center> Record not found </center></td></tr>";
}
?>
</table>
</body>
</html>

Output:-

Booking :-

33
Tybca-div-2-sem-5 PHP & MYSQL Roll no-102

Cust_mast:-

Room_mast :-

34

You might also like