Anda di halaman 1dari 12

ESOFT METRO CAMPUS - JAFFNA DIWE

Database Building

Database Name Table Name

connect.php
<?php
mysql_connect("localhost","root","") or
die (mysql_error());
mysql_select_db ("test_db");
?>

index.php
<html>
<head>
<title>Student Information</title>
<link rel="stylesheet" type="text/css"
href="Style/viewtablesearch.css" />
</head>
<body>
<center><h1>Welcome to Student</h1></center>

<a class="addnew" href="Add_Form.php" style="font-face:Khmer OS


Battambang; font-size:16px;">New Record </a>

<div class="search">
<form method="post" action="searchidandname.php">
<select name="cbosearch">
<option>ID</option>
<option>Name</option>
<option>Gender</option>
Page 1 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<option>Address</option>
</select>
<input type="text" name="txtsearch" placeholder="Type
to Search" /><input type="submit" name="cmdsearch"
value="Search" />
</form>
</div>
<table>
<tr>
<th>StuID</th>
<th>StuName</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Address</th>
<th>Subject</th>
<th>Registered Date</th>
<th>Option</th>
</tr>

<?php
include "connect.php";
$i = "select * from tbl_student";
$h = mysql_query($i);
while($tr=mysql_fetch_array($h))
{
?>
<tr>
<td><?php echo $tr[0]; ?></td>
<td><?php echo $tr[1]; ?></td>
<td><?php echo $tr[2]; ?></td>
<td><?php echo $tr[3]; ?></td>
<td><?php echo $tr[4]; ?></td>
<td><?php echo $tr[5]; ?></td>
<td><?php echo $tr[6]; ?></td>
<td align="center"><a href="Delete_Form.php? txtid=<?
php echo $tr[0];?>">Delete</a> / <a href="Edit_Form.php? txtid=<?
php echo $tr[0];?>">Edit</a> </td>
</tr>
<?php
}
?>

</table>
</body>
</html>

Page 2 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

Add_Form.php
<html>
<head>
<title>Add Form</title>
<link href="Style/Add_Form.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#99CC66" background="Images/MyBackground.png">


<div class="img"><img src="Images/auditoria.png" /></div>
<div class="ii"><center><img src="Images/Edit_Yes.png"
style="margin-top:20px"/></center></div>
<div id="topbar">
<center><h1 style="color:#939">Welcome to Add Form</h1>
</div>
<div id="form">
<table>
<form method="post" action="?action=new_stu">
<tr>

<?php
include ("connect.php");
$g = mysql_query("select max(stuid) from tbl_student");
while($id=mysql_fetch_array($g))
{
?>

<th>ID:</th>
<td><input type="text" name="txtid" value="<?php echo
$id[0]+1; ?>" readonly="readonly" /></td>
</tr>
<?php
}
?>
<tr>
<th>Name:</th>
<td><input type="text" name="txtname" placeholder="Type
Name" /></td>
</tr>
<tr>
<th>Gender:</th>
<td><select name="txtgender">
<option>Select Gender</option>
<option>Male</option>
<option>Felmale</option>
</select>
</td>
</tr>
Page 3 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<tr>
<th>Date of Birth:</th>
<td>
<select name="txtday">
<option>Day</option>
<?php
$d=0;
do{
$d++;
echo "<option>".$d."</option>";
}while($d<=30);
?>
</select>
<select name="txtmonth">
<option>Month</option>
<?php
//For Loop

$m=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct
","Nov","Dec");
for($i=0;$i<count($m);$i++){
echo"<option>".$m[$i]."</option>";
}
?>

</select>
<select name="txtyear">
<option>Year</option>
<?php
//While Loop
$y=2021;
while($y>=1950){
$y--;
echo "<option>".$y."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<th>Address:</th>
<td><textarea cols="19px" rows="3"
name="txtaddress" placeholder="Type Your Address"
/></textarea></td>
</tr>
<tr>
<th>Subject:</th>
<td>
Page 4 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<select name="txtsubject">
<option>Select Subject</option>
<?php
$s=array("Java
Script","VB.NET","Graphic Design","PHP & MySQL","C#","C","C+
+","VBA","HTML and CSS");
for($i=0;$i<count($s);$i++)
{
echo "<option>".$s[$i]."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<th>Register Date:</th>
<td><input type="text" name="txtdate" value="<?
php echo date("d/M/Y"); ?>" readonly="readonly" /></td>
</tr>
<tr>
<td><input type="submit" name="cmdadd"
value="Add" /></td>
<td><input type="reset" name="cmdreset"
value="Clear"/></td>
</tr>
</form>
</table>
</div>
<?php
if(isset($_GET["action"])=="new_stu")
{
$id = $_POST['txtid'];
$name = trim($_POST['txtname']);
$gender = trim($_POST['txtgender']);
$dob = trim($_POST['txtday']."/".$_POST['txtmonth']."/".
$_POST['txtyear']);
$address = trim($_POST['txtaddress']);
$sub = trim($_POST['txtsubject']);
$date = trim($_POST['txtdate']);
if(isset($_POST['cmdadd'])) {
if (empty($name) || $gender == "Select Gender" ||
$_POST['txtday'] == "Day" || $_POST['txtmonth'] == "Month" ||
$_POST['txtyear'] == "Year" || empty($address) || $subject ==
"Select Subject") {
echo "<center>Sorry please input data</center>";
} else {
include "connect.php";
$i = mysql_query("insert into tbl_student values('"
Page 5 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

. $id . "','" . $name . "','" . $gender . "','" . $dob . "','" .


$address . "','" . $sub . "','" . $date . "')");
if ($i == true) {
echo '<META HTTP-EQUIV="Refresh" Content="0;
URL=index.php">';
}

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

Edit_Form.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-
8" />
<title>Edit Form</title>

<link rel="stylesheet" type="text/css"


href="Style/Edit_Form.css" />

</head>

<body background="Images/MyBackground.png" bgcolor="#FFCC99">


<div class="topbar"> <h1 style="color:#FFF"><center>Edit
Form</center></h1></div>
<center>
<div class="box">
<?php

$id = $_GET['txtid'];
include ("connect.php");
$i ="select * from tbl_student where stuid=".$id;
$h= mysql_query($i);
if($tr=mysql_fetch_array($h))
{
?>
<table><form method="post" action="">
<tr>
<th>ID:</th>

Page 6 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<td><input type="text" name="txtid" value="<?php echo


$tr[0]; ?>"/></td>
</tr>
<tr>
<th>Name:</th>
<td><input type="text" name="txtname" value="<?php echo
$tr[1]; ?>" /></td>
</tr>
<tr>
<th>Gender:</th>
<td>
<input type="text" name="txtgender" value="<?php echo
$tr[2]; ?>" /></td>
</td>
</tr>
<tr>
<th>Date of Birth:</th>
<td><input type="text" name="txtdob" value="<?php echo
$tr[3]; ?>" /></td>
</tr>
<tr>
<th>Address:</th>
<td><textarea cols="16" rows="3" name="txtaddress"> <?php
echo $tr[4];?> </textarea></td>
</tr>
<tr>
<th>Subject:</th>
<td><input type="text" name="txtsubject" value="<?php
echo $tr[5]; ?>" /></td>
</tr>
<tr>
<th>Edited Date:</th>
<td><input type="text" name="txtdate" value="<?php echo
$tr[6];?>"/></td>
</tr>
<?php
}
?>
<td colspan="2" align="center"><input type="submit"
name="cmdedit" value="Save" />
<a href="index.php"><img src="Images/Users_Group.png"
title="Go Back"/></a>
</td>
</tr>
</form></table>
</div>
</center>
<?php
Page 7 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

include ("connect.php");
$i = mysql_query("update tbl_student set name='".
$_POST['txtname']."', gender='".$_POST['txtgender']."', dob='".
$_POST['txtdob']."', address='".trim($_POST['txtaddress'])."',
sub='".$_POST['txtsubject']."', date='".$_POST['txtdate']."' where
stuid=".$_POST['txtid']);
if($i==true){
echo '<META HTTP-EQUIV="Refresh" Content="0;
URL=index.php">';
}

?>
</body>
</html>

Delete_Form.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Form</title>
<link href="Style/Delete_Form.css" type="text/css" rel="stylesheet"
/>
</head>

<body background="Images/MyBackground.png" bgcolor="#999966">


<div class="topbar"><center><h1 style="color:#FFF">Delete
Form</h1></center></div>
<div id="box"><center>

<?php

$id = $_GET['txtid'];
include ("connect.php");
$i = "select * from tbl_student where stuid=".$id;
$h = mysql_query($i);
if($tr=mysql_fetch_array($h))
{
?>

<table>
<form method="post" action="">
<tr>
<th>ID:</th>
<td><input type="text" name="txtid" value="<?php echo
$tr[0]; ?>" /></td>
</tr>
<tr>
<th>Name:</th>
Page 8 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<td><input type="text" name="txtname" value="<?php echo


$tr[1]; ?>"/></td>
</tr>
<tr>
<th>Gender:</th>
<td><input type="text" name="txtgender" value="<?php echo
$tr[2]; ?>" /></td>
</tr>
<tr>
<th>Date of Birth:</th>
<td><input type="text" name="txtdob" value="<?php echo
$tr[3]; ?>" /></td>
</tr>
<tr>
<th>Address:</th>
<td><textarea name="txtaddress" cols="14px" rows="3"><?php
echo $tr[4]; ?></textarea></td>
</tr>
<tr>
<th>Subject:</th>
<td><input type="text" name="txtsub" value="<?php echo
$tr[5]; ?>" /></td>
</tr>
<tr>
<th>Deleted Date</th>
<td><input type="text" name="txtdate" value="<?php echo
$tr[6]; ?>" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" align="center">
<input type="submit" name="cmddelete" value="Delete"/>
<a href="index.php"><img src="Images/Users_Group.png"
title="Go Back" /></a>
</td>
</tr>
</form>
</table></center>
</div>
<?php
$id=$_POST['txtid'];
include("connect.php");
$i = mysql_query("delete from tbl_student where stuid=".$id);
if($i==true){
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">';
}
?>
</body>
</html>

Page 9 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

Searchidname.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search by ID</title>
<link rel="stylesheet" type="text/css"
href="Style/viewtablesearch.css" />
</head>

<body>
<center><h1>Search Result</h1></center>
<a class="addnew" href="index.php" style="font-face:Khmer OS Battambang;
font-size:16px;">New Student</a></font>
<table>
<tr>
<th>StuID</th>
<th>StuName</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Address</th>
<th>Subject</th>
<th>Registered Date</th>
<th>Option</th>
</tr>
<?php
$text = $_POST['txtsearch'];
if($text==""){
echo "No Data....Please Try Again!!!"."<br>";
echo '<a href="ViewTable.php"><img
src="Images/Users_Group.png" title="Go Back"></a>';
}
?>
<?php
$cbo = $_POST['cbosearch'];
$search = $_POST['txtsearch'];
include('connect.php');
?>
<?php
if($cbo=="ID")
{
$id = mysql_query("SELECT * FROM tbl_student WHERE
stuid='$search'");
?>

<?php
while($di=mysql_fetch_array($id))
{
?>
<tr>
<td><?php echo $di[0]; ?></td>

Page 10 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<td><?php echo $di[1]; ?></td>


<td><?php echo $di[2]; ?></td>
<td><?php echo $di[3]; ?></td>
<td><?php echo $di[4]; ?></td>
<td><?php echo $di[5]; ?></td>
<td><?php echo $di[6]; ?></td>
<td align="center"><a href="Delete_Form.php?
txtid=<?php echo $di[0];?>">Delete</a> / <a href="Edit_Form.php?
txtid=<?php echo $di[0];?>">Edit</a></td>
</tr>
<?php
}
}else if($cbo=="Name")
{
$na = mysql_query("SELECT * FROM tbl_student WHERE name
like '".$search."%'");
?>
<?php
while($an=mysql_fetch_array($na))
{
?>
<tr>
<td><?php echo $an[0]; ?></td>
<td><?php echo $an[1]; ?></td>
<td><?php echo $an[2]; ?></td>
<td><?php echo $an[3]; ?></td>
<td><?php echo $an[4]; ?></td>
<td><?php echo $an[5]; ?></td>
<td><?php echo $an[6]; ?></td>
<td align="center"><a href="Delete_Form.php?
txtid=<?php echo $an[0];?>">Delete</a> / <a href="Edit_Form.php?
txtid=<?php echo $an[0];?>">Edit</a></td>
</tr>
<?php
}
?>
<?php
}else if($cbo=="Address")
{
$add = mysql_query("SELECT * FROM tbl_student WHERE address like
'".$search."%'");
?>
<?php
while($dda=mysql_fetch_array($add))
{
?>
<tr>
<td><?php echo $dda[0]; ?></td>
<td><?php echo $dda[1]; ?></td>
<td><?php echo $dda[2]; ?></td>
<td><?php echo $dda[3]; ?></td>
<td><?php echo $dda[4]; ?></td>
Page 11 of 12
ESOFT METRO CAMPUS - JAFFNA DIWE

<td><?php echo $dda[5]; ?></td>


<td><?php echo $dda[6]; ?></td>
<td align="center"><a href="Delete_Form.php?txtid=<?
php echo $dda[0];?>">Delete</a> / <a href="Edit_Form.php?txtid=<?php
echo $dda[0];?>">Edit</a></td>
</tr>
<?php
}
}else if($cbo=="Gender")
{
$g = mysql_query("SELECT * FROM tbl_student WHERE gender
like '".$search."%'");
?>
<?php
while($ge=mysql_fetch_array($g))
{
?>
<tr>
<td><?php echo $ge[0]; ?></td>
<td><?php echo $ge[1]; ?></td>
<td><?php echo $ge[2]; ?></td>
<td><?php echo $ge[3]; ?></td>
<td><?php echo $ge[4]; ?></td>
<td><?php echo $ge[5]; ?></td>
<td><?php echo $ge[6]; ?></td>
<td align="center"><a href="Delete_Form.php?txtid=<?
php echo $ge[0];?>">Delete</a> / <a href="Edit_Form.php?txtid=<?php echo
$ge[0];?>">Edit</a></td>
</tr>

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

Page 12 of 12

Anda mungkin juga menyukai