Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
85 views

PHP - 2

This document describes a PHP application that allows users to insert, update, and delete records in an employee database table. The main index.php page displays the employee table and includes buttons to insert, update, or delete records. Clicking a button loads the corresponding form page (insert.php, update.php, delete.php), which collects the needed input fields and submits back to index.php. Index.php then performs the SQL operation and redirects back to itself on success.

Uploaded by

SupriyaBhoir
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

PHP - 2

This document describes a PHP application that allows users to insert, update, and delete records in an employee database table. The main index.php page displays the employee table and includes buttons to insert, update, or delete records. Clicking a button loads the corresponding form page (insert.php, update.php, delete.php), which collects the needed input fields and submits back to index.php. Index.php then performs the SQL operation and redirects back to itself on success.

Uploaded by

SupriyaBhoir
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Page 1

Sr.
No.
Title
Page
No.
Sign.
1 Insert, Update and Delete 2




2 Registration Form 9





Page 2
1. Insert Update and Delete :-

Index.php :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#div1
Page 3
{
text-align:left;
width:300px;
}
</style>
</head>
<body>
<?php
if(isset($_GET["btnsubmit"]))
{
mysql_connect("localhost","root","");
mysql_select_db("employee");
$op=$_GET["btnsubmit"];
switch($op)
{
case "Insert":
$name=$_GET['txtname'];
$salary=$_GET['txtsal'];
$des=$_GET['txtdes'];
$s="insert into emp(name,salary,designation)
values('$name',$salary,'$des')";
break;
case "Update":
$id=$_GET['txtid'];
$name=$_GET['txtname'];
Page 4
$salary=$_GET['txtsal'];
$des=$_GET['txtdes'];
$s="UPDATE emp SET
name='$name',salary=$salary,designation='$des' where id=$id";
break;
case "Delete":
$id=$_GET['txtid'];
$s="delete from emp where id=$id";
break;
}
$data=mysql_query($s);
if($data)
{
header("Location:index.php");
}
}
?>
<center>
<div id="div1">
<table border="2">
<?php
mysql_connect("localhost","root","");
mysql_select_db("employee");
$data=mysql_query("select * from emp");
Page 5
echo "<tr><td>Emp No</td><td>Emp
Name</td><td>Salary</td><td>Designation</td></tr>";
while($row=mysql_fetch_array($data))
{
echo "<tr>";
echo "<td>".$row["id"]."</td>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["salary"]."</td>";
echo "<td>".$row["designation"]."</td>";
echo "</tr>";
}
?>
</table>
<div>
<form method="get">
<input type="submit" name="btnsub"
value="Insert" />
<input type="submit" name="btnsub"
value="Update" />
<input type="submit" name="btnsub"
value="Delete" />
</form>
</div>
<div>
<?php
if(isset($_GET["btnsub"]))
Page 6
{
$op=$_GET["btnsub"];
switch($op)
{
case "Insert":
include("insert.php");
break;
case "Update":
include("update.php");
break;
case "Delete":
include("delete.php");
break;
}
}
?>
</div>
</div>
</center>
</body>
</html>
Insert.php :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Page 7
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="index.php" method="get">
Name : <input type="text" name="txtname" /><br />
Salary : <input type="text" name="txtsal" /><br />
Designation : <input type="text" name="txtdes" /><br />
<input type="submit" name="btnsubmit" value="Insert" />
</form>
</body>
</html>
Update.php :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
Page 8
<form action="index.php" method="get">
ID : <input type="text" name="txtid" /><br />
Name : <input type="text" name="txtname" /><br />
Salary : <input type="text" name="txtsal" /><br />
Designation : <input type="text" name="txtdes" /><br />
<input type="submit" name="btnsubmit" value="Update" />
</form>
</body>
</html>
Delete.php :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="index.php" method="get">
ID : <input type="text" name="txtid" /><br />
<input type="submit" name="btnsubmit" value="Delete" />
</form>
</body>
</html>

You might also like