Reader Level:
ARTICLE

Insert Edit Delete Pagination in PHP

Posted by Satyapriya Nayak Articles | PHP June 04, 2012
In this article we will know how to insert, edit, update and delete records from the database with pagination using php.
  • 2
  • 0
  • 12823
 

Introduction

In this article we will learn how to insert, edit, update and delete records from the database with pagination using PHP. In this application I have created a simple header section, footer section and a menu section. In the menu section there are two links as Add Members link and List of Members link. We add new members in Add Members link and to view the total members we go for List of Members link. Here we use JavaScript for the validations. Here paging facilities will be used when more than 5 records from the database have been found. We can also determine the total records available in the database.

Table Creation

-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 04, 2012 at 09:58 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `homework`
--

-- --------------------------------------------------------

--
-- Table structure for table `employee`
--

CREATE TABLE `employee` (
`id` int(11) NOT NULL auto_increment,
`regno` varchar(255) NOT NULL,
`mdate` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`dob` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`city` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`pin` varchar(255) NOT NULL,
`phno` varchar(255) NOT NULL,
`amount` varchar(255) NOT NULL,
`years` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `employee`
--

INSERT INTO `employee` (`id`, `regno`, `mdate`, `name`, `dob`, `address`, `city`, `state`, `country`, `pin`, `phno`, `amount`, `years`) VALUES
(1, 'E00-0', '01/05/2010', 'Raj', '01/06/2012', '200, 8180 Macleod Trail SE', 'Pune', 'Maharastra', 'India', '75100', '2301325', '1000', '2012'),
(2, 'E00-2', '02/05/2012', 'Ravi', '02/06/2012', '1521 - 34th Avenue SE', 'Mumbai', 'Maharastra', 'India', '75101', '2301326', '2000', '2012'),
(3, 'E00-3', '03/05/2012', 'Rahul', '03/06/2012', '39 Alpine Blvd', 'Bhubaneswar', 'Orissa', 'India', '751013', '2301327', '3000', '2012'),
(4, 'E00-4', '04/05/2012', 'Harry', '04/06/2012', '204, 59 - 22 Ave SW', 'Calgary', 'Alberta', 'Canada', '751014', '2301328', '4000', '2012'),
(5, 'E00-5', '05/05/2012', 'Ian', '05/06/2012', '330 MacKenzie Blvd', 'Fort McMurray', 'Alberta', 'Canada', '751015', '2301329', '5000', '2012'),
(6, 'E00-6', '06/05/2012', 'Ben', '06/06/2012', '730 Fountain St N', 'Cambridge', 'Ontario', 'Canada', '751019', '2301310', '6000', '2012'),
(7, 'E00-7', '07/05/2012', 'Ken Milne', '07/06/2012', '902 - 20th Avenue', 'Nisku', 'Alberta', 'Canada', '851010', '3013256', '7000', '2012'),
(8, 'E00-8', '08/05/2012', 'Kevin Potter', '08/06/2012', '550 West Adams Street', 'Chicago', 'Illinois', 'Usa', '962312', '2365214', '8000', '2012'),
(9, 'E00-9', '09/05/2012', 'Leana Ross', '09/06/2012', '1800,324-8th Ave SW', 'Vancouver', 'British Columbia', 'Canada', '5623215', '2321564', '9000', '2012'),
(10, 'E00-10', '10/05/2012', 'Linda Reynolds', '10/06/2012', '150 - 9Ave SW', 'Calgary', 'Alberta', 'Canada', '5325645', '23013256', '10000', '2012');


Now lets move to the coding part

For creating database connection

Config.php

<?php

$sDbHost = 'localhost';
$sDbName = 'homework';
$sDbUser = 'root';
$sDbPwd = '';

$dbConn = mysql_connect ($sDbHost, $sDbUser, $sDbPwd) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($sDbName,$dbConn) or die('Cannot select database. ' . mysql_error());

?>

For adding employee to database

employee.php

<?php include("config.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=iso-8859-1" />
<title>Employee</title>
<script language="javascript" type="text/javascript">

function validate()
{
if(document.frm.regno.value=="")
{
alert("Please Enter Regno");
document.frm.regno.focus();
return false;
}

if(document.frm.mdate.value=="")
{
alert("Please Enter Date !!");
document.frm.mdate.focus();
return false;
}


if(document.frm.name.value=="")
{
alert("Please Enter Your Name !!");
document.frm.name.focus();
return false;
}

if(!(isNaN(document.frm.name.value)))
{
alert("Name has character only!");
return false;
}

if(document.frm.dob.value=="")
{
alert("Please Select your Date of Birth !!");
document.frm.dob.focus();
return false;
}

if(document.frm.address.value=="")
{
alert("Please Enter Address !!");
document.frm.address.focus();
return false;
}

if(document.frm.city.value=="")
{
alert("Please Enter City !!");
document.frm.city.focus();
return false;
}

if(!(isNaN(document.frm.city.value)))
{
alert("City has character only!");
return false;
}

if(document.frm.state.value=="")
{
alert("Please Enter State !!");
document.frm.state.focus();
return false;
}

if(!(isNaN(document.frm.state.value)))
{
alert("State has character only!");
return false;
}

if(document.frm.country.value=="")
{
alert("Please Enter Country !!");
document.frm.country.focus();
return false;
}

if(!(isNaN(document.frm.country.value)))
{
alert("Country has character only!");
return false;
}

if(document.frm.pin.value=="")
{
alert("Please Enter Pincode !!");
document.frm.pin.focus();
return false;
}

if(document.frm.pin.value=="")
{
alert("Please Enter Pincode !!");
document.frm.pin.focus();
return false;
}

if((isNaN(document.frm.pin.value)))
{
alert("Pincode has numeric only!");
return false;
}

if(document.frm.phno.value=="")
{
alert("Please Enter Phone number !!");
document.frm.phno.focus();
return false;
}

if((isNaN(document.frm.phno.value)))
{
alert("Phone number has numeric only!");
return false;
}

if(document.frm.amount.value=="")
{
alert("Please Enter Amount !!");
document.frm.amount.focus();
return false;
}

if((isNaN(document.frm.amount.value)))
{
alert("Amount has numeric only!");
return false;
}
return true;
}

</script>
<link href="css/activenews_styles.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script type="text/javascript" src="calendar/calendar-en.js"></script>
<style type="text/css">
@import url("calendar/calendar-blue.css");
.style14 {color: #000000}
</style>
</head>
<body>
<?php
if($_REQUEST["Submit"]=="View")
{
echo "<script>location.href='item_details.php?qs=view'</script>";
}
?>
<?php
if($_REQUEST["save"]=="Save")
{
$qry="select regno from employee where regno='".$_REQUEST["regno"]."'";
$rows=mysql_query($qry);
if(mysql_num_rows($rows)>0)
{
$msg="Don't Use Refresh Buttom";
}
else
{
$regno=$_REQUEST["regno"];
$mdate=$_REQUEST["mdate"];
$name=$_REQUEST["name"];
$dob=$_REQUEST["dob"];
$address=$_REQUEST["address"];
$city=$_REQUEST["city"];
$state=$_REQUEST["state"];
$country=$_REQUEST["country"];
$pin=$_REQUEST["pin"];
$phno=$_REQUEST["phno"];
$amount=$_REQUEST["amount"];

$str="insert into employee(regno,mdate,name,dob,address,city,state,country,pin,phno,amount,years)values('".$regno."','".$mdate."','".$name."','".$dob."','".$address."','".$city."','".$state."','".$country."','".$pin."','".$phno."','".$amount."','".date("Y")."')";
mysql_query($str);
}
}
?>
<form action="employee.php" method="post" name="frm" id"frm" onSubmit="return validate()";>
<?php
$str="select ifnull(max(id)+1,0) as maxval from employee";
$res=mysql_query($str);
$row=mysql_fetch_assoc($res);
$str1="E00-".$row["maxval"];
?>
<table width="100%" border="0" align="center">
<tr>
<td height="132" colspan="2"><?php include("../Insert Edit Delete pagination/include/banner.php");?></td>
</tr>
<tr>
<td width="204" height="423"><?php include("../Insert Edit Delete pagination/include/menu.php");?></td>
<td width="738"><table width="725" border="1" align="center">
<tr>
<td colspan="3"><strong>Employee</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $msg; ?></td>
</tr>
<tr>
<td width="149">Reg. No.</td>
<td width="270"><input type="text" name="regno" size="45" readonly value="<?php echo $str1; ?>"/></td>
<td width="284" rowspan="11">&nbsp;</td>
</tr>

<tr>
<td align="left">Join Date: </td>
<td><input name="mdate" type="text" id="date" readonly="readonly" size="40" value=""/>
<img src="../Insert Edit Delete pagination/img/calc2.gif" id="cal-button-2" width="14" height="14" alt="" border="0" />
<script type="text/javascript">
Calendar.setup({
inputField : "date",
button : "cal-button-2",
align : "Td"
});

</script> </td>
</tr>
<tr>
<td align="left">Name:</td>
<td><input type="text" name="name" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td align="left">DOB: </td>
<td><input name="dob" type="text" id="date1" readonly="readonly" size="40" value=""/>
<img src="../Insert Edit Delete pagination/img/calc2.gif" id="cal-button-3" width="14" height="14" alt="" border="0" />
<script type="text/javascript">
Calendar.setup({
inputField : "date1",
button : "cal-button-3",
align : "Td"
});

</script> </td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="state" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>Country:</td>
<td><input type="text" name="country" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>Pincode:</td>
<td><input type="text" name="pin" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>Phone No:</td>
<td><input type="text" name="phno" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" size="45" autocomplete="off"/></td>
</tr>
<tr>
<td height="29" colspan="3" align="center"><input name="save" type="submit" value="Save" />
<span class="subhead">
<input type="button" name="Submit2" value="View" onclick="javascript:location.href='employee_members.php'" />
</span></td>
</tr>
</table></td>
</tr>
<tr>
<td height="23" colspan="2"><?php include("../Insert Edit Delete pagination/include/footer.php");?></td>
</tr>
</table>
</form>
</body>
</html>


To view employee

employee_members.php

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

if(isset($_GET['task']) && trim($_GET['task'])=="delete")
{
$del="delete from employee where id='".$_GET['id']."'";

mysql_query($del) or die(mysql_error());

}
?>
<!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=iso-8859-1" />
<title>Employee Members</title>
<link href="css/activenews_styles.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script type="text/javascript" src="calendar/calendar-en.js"></script>
<style type="text/css">
@import url("calendar/calendar-blue.css");
</style>
</head>
<body>
<form action="employee.php" method="post" name="frm">

<table width="100%" border="0" align="center">
<tr>
<td height="132" colspan="2"><?php include("../Insert Edit Delete pagination/include/banner1.php");?></td>
</tr>
<tr>
<td width="204" height="423"><?php include("../Insert Edit Delete pagination/include/menu.php");?></td>
<td><table width="760" border="1">
<tr>
<td height="35" colspan="7"><strong>Members Information</strong></td>
</tr>
<?php
//*******************************************PAGINATION************************************************
if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
}
else
{
$pageno = 1;
}
$query = "SELECT count(*) FROM employee";

$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

$query_data = mysql_fetch_row($result);

$numrows = $query_data[0];

echo "<b>Total Members:</b>";echo $numrows;
echo "<br><br>";
//3. Calculate number of $lastpage
//This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page.

$rows_per_page = 5;

$lastpage = ceil($numrows/$rows_per_page);

//4. Ensure that $pageno is within range
//This code checks that the value of $pageno is an integer between 1 and $lastpage.

$pageno = (int)$pageno;
if ($pageno > $lastpage)
{
$pageno = $lastpage;
}
if ($pageno < 1)
{
$pageno = 1;
}


//5. Construct LIMIT clause
//This code will construct the LIMIT clause for the sql SELECT statement.

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

//$query = "SELECT * FROM user $limit";
//$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);


?>
<tr>
<td width="61" align="center"><strong>Reg.No.</strong></td>
<td width="83" align="center"><strong>MDate</strong></td>
<td width="172" align="center"><strong>Name</strong></td>
<td width="93" align="center"><strong>State</strong></td>
<td width="94" align="center"><strong>Phone No.</strong></td>
<td width="99" align="center"><strong>Member Details </strong></td>
<td width="112" align="center"><strong>Action</strong></td>
</tr>
<?php
if($_REQUEST["cnt"]!="")
{
$count=$_REQUEST["cnt"];
$cntprev=$count-2;
}
else
{
$count=1;
}
$sql="select * from employee $limit";
$rs=mysql_query( $sql);
while($row=mysql_fetch_assoc($rs))
{
?>
<tr>
<td height="30" align="center"><?php echo $row["regno"];?></td>
<td align="center"><?php echo $row["mdate"];?></td>
<td align="center"><?php echo $row["name"];?></td>
<td align="center"><?php echo $row["state"];?></td>
<td align="center"><?php echo $row["phno"];?></td>
<td align="center"><a href="employee_information.php?id=<?php echo $row['id']; ?>"/>[ Details ]</td>
<td align="center">[ <a href="employee_members.php?task=delete&amp;id=<?php echo $row['id'];?>" onclick="return confirm('Are you sure want to delete?');" class="hlinkinner"> Delete</a>&nbsp;][ <a href="edit_members.php?task=edit&amp;id=<?php echo $row['id'];?>"> Edit</a>&nbsp;] </td>
</tr>
<?php
$count= $count+1;
}
?>
<tr>
<td height="31" colspan="7" align="center"><?php

//7. Construct pagination hyperlinks
//Finally we must construct the hyperlinks which will allow the user to select other pages. We will start with the links for any previous pages.

if ($pageno == 1)
{
echo " FIRST PREV ";
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1&cnt=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&cnt=".$cntprev."'>PREV</a> ";
}
echo "(Page $pageno of $lastpage)";
if ($pageno == $lastpage)
{
echo " NEXT LAST ";
}
else
{
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&cnt=$count'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&cnt=$numrows'>LAST</a> ";
}
//***************************************Pagination End****************************************
?></td>
</tr>
</table></td>
</tr>
<tr>
<td height="23" colspan="2"><?php include("../Insert Edit Delete pagination/include/footer.php");?></td>
</tr>
</table>
</form>
</body>
</html>


To edit employee

edit_members.php

<?php
include("config.php");
$id=$_GET["id"];
?>
<!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=iso-8859-1" />
<title>Edit Employee Information</title>
<script language="javascript" type="text/javascript">
function validate()
{
if(document.getElementById("regno").value=="")
{
alert("Registration Number can not be Blank !!");
document.getElementById("regno").focus();
return false;
}
if(document.getElementById("mdate").value=="")
{
alert("Date can not Blank !!");
document.getElementById("mdate").focus();
return false;
}
if(document.getElementById("name").value=="")
{
alert("Enter Your Name !!");
document.getElementById("name").focus();
return false;
}
if(document.getElementById("dob").value=="")
{
alert("Select your Date of Birth !!");
document.getElementById("dob").focus();
return false;
}
if(document.getElementById("address").value=="")
{
alert("Address can not Blank !!");
document.getElementById("address").focus();
return false;
}
if(document.getElementById("city").value=="")
{
alert("City Can not Blank !!");
document.getElementById("city").focus();
return false;
}
if(document.getElementById("state").value=="")
{
alert("State Can not Blank !!");
document.getElementById("state").focus();
return false;
}
if(document.getElementById("country").value=="")
{
alert("Country Can not Blank !!");
document.getElementById("country").focus();
return false;
}
if(document.getElementById("pin").value=="")
{
alert("Pin Number Can not Blank !!");
document.getElementById("pin").focus();
return false;
}
if(isNaN(document.getElementById("pin").value))
{
alert("Pin Number should be Numeirc !!");
document.getElementById("pin").focus();
return false;
}
if(document.getElementById("phno").value=="")
{
alert("Phone Number Can not Blank !!");
document.getElementById("phno").focus();
return false;
}
if(document.getElementById("amount").value=="")
{
alert("Amount Can not Blank !!");
document.getElementById("amount").focus();
return false;
}
if(isNaN(document.getElementById("amount").value))
{
alert("Amount should be Numeirc !!");
document.getElementById("amount").focus();
return false;
}
return true;
}
</script>
<link href="css/activenews_styles.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script type="text/javascript" src="calendar/calendar-en.js"></script>
<style type="text/css">
@import url("calendar/calendar-blue.css");
.style14 {color: #000000}
</style>
</head>
<body>
<?php
if($_REQUEST["Submit"]=="Update")
{
$regno=$_REQUEST["regno"];
$mdate=$_REQUEST["mdate"];
$name=$_REQUEST["name"];
$dob=$_REQUEST["dob"];
$address=$_REQUEST["address"];
$city=$_REQUEST["city"];
$state=$_REQUEST["state"];
$country=$_REQUEST["country"];
$pin=$_REQUEST["pin"];
$phno=$_REQUEST["phno"];
$amount=$_REQUEST["amount"];
$hidden_id=$_REQUEST["hidden_id"];

// echo $barcode;
// exit;
$str="update employee set regno='".$regno."',mdate='".$mdate."',name ='".$name."',dob='".$dob."',address='".$address."',city='".$city."',state='".$state."',country='".$country."',pin='".$pin."',phno='".$phno."',amount='".$amount."' where id=".$hidden_id."";
//echo $str;
//exit;
mysql_query($str);
echo "<script>location.href='employee_members.php'</script>";

}
?>
<form action="edit_members.php" method="post" name="Edit Members" onSubmit="return validate()";>
<table width="100%" border="0" align="center">
<tr>
<td height="132" colspan="2"><?php include("../Insert Edit Delete pagination/include/banner2.php");?></td>
</tr>
<tr>
<td width="204" height="423"><?php include("../Insert Edit Delete pagination/include/menu.php");?></td>
<td width="738"><table width="725" border="1" align="center">
<tr>
<td height="31" colspan="3"><strong>Employee Information</strong></td>
</tr>
<?php
$sql="SELECT * FROM employee where id='".$id."'";
$result=mysql_query($sql) or die(mysql_error());
//echo $sql;
//exit;
$rows=mysql_num_rows($result);
while($row = mysql_fetch_assoc($result))
{
$i = 1;
?>
<tr>
<td width="149">Reg. No.</td>
<td width="270"><input type="hidden" name="hidden_id" size="80" value="<?php echo $row["id"]; ?>"><input type="text" name="regno" size="45" readonly value="<?php echo $row["regno"]; ?>"/></td>
<td width="284" rowspan="11">&nbsp;</td>
</tr>

<tr>
<td align="left">Join Date </td>
<td><input name="mdate" type="text" id="date" size="40" value="<?php echo $row["mdate"]; ?>"/>
<img src="../Insert Edit Delete pagination/img/calc2.gif" id="cal-button-2" width="14" height="14" alt="" border="0" />
<script type="text/javascript">
Calendar.setup({
inputField : "date",
button : "cal-button-2",
align : "Td"
});

</script> </td>
</tr>
<tr>
<td align="left">Name:</td>
<td><input type="text" name="name" size="45" value="<?php echo $row["name"]; ?>"/></td>
</tr>
<tr>
<td align="left">DOB </td>
<td><input name="dob" type="text" id="date1" size="40" value="<?php echo $row["dob"]; ?>"/>
<img src="../Insert Edit Delete pagination/img/calc2.gif" id="cal-button-3" width="14" height="14" alt="" border="0" />
<script type="text/javascript">
Calendar.setup({
inputField : "date1",
button : "cal-button-3",
align : "Td"
});

</script> </td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" size="45" value="<?php echo $row["address"]; ?>"/></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" size="45" value="<?php echo $row["city"]; ?>"/></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="state" size="45" value="<?php echo $row["state"]; ?>"/></td>
</tr>
<tr>
<td>Country:</td>
<td><input type="text" name="country" size="45" value="<?php echo $row["country"]; ?>"/></td>
</tr>
<tr>
<td>Pin:</td>
<td><input type="text" name="pin" size="45" value="<?php echo $row["pin"]; ?>"/></td>
</tr>
<tr>
<td>Phone No:</td>
<td><input type="text" name="phno" size="45" value="<?php echo $row["phno"]; ?>"/></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" size="45" value="<?php echo $row["amount"]; ?>"/></td>
</tr>
<tr>
<td height="29" colspan="3" align="center"><input type="submit" name="Submit" value="Update" />
<input name="Button" type="button" class="button" id="Submit" onclick="window.location='employee_members.php';" value="Cancel"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="23" colspan="2"><?php include("../Insert Edit Delete pagination/include/footer.php");?></td>
</tr>
</table>
<?php
$i++;
}
?>
</form>
</body>
</html>


employee_information.php

<?php include("config.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=iso-8859-1" />
<title>Members Information</title>
<script language="javascript" type="text/javascript">
function hides()
{
//alert("z");
document.getElementById("head").style.display="none";
document.getElementById("foot").style.display="none";
document.getElementById("left").style.display="none";
document.getElementById("prints").style.display="none";
document.getElementById("tb1").valign="bottom";

}
</script>
</head>
<body>
<?php
$id=$_GET["id"];
$sql="SELECT * FROM employee where id='".$id."'";
$result=mysql_query($sql) or die(mysql_error());
$rows=mysql_num_rows($result);
while($row = mysql_fetch_assoc($result))
{
$i = 1;
?>
<form action="employee_information.php" method="post" name="employee">
<table width="100%" border="0" align="center">
<tr>
<td height="132" colspan="2" id="head"><?php include("../Insert Edit Delete pagination/include/banner1.php");?></td>
</tr>
<tr>
<td width="204" height="423" id="left"><?php include("../Insert Edit Delete pagination/include/menu.php");?></td>
<td width="738" id="tb1"><table width="543" border="1" align="center">
<tr>
<td height="30" colspan="3"><strong>Members Information</strong></td>
</tr>
<tr>
<td width="253">Reg. No.</td>
<td width="274"><?php echo $row["regno"]; ?></td>
</tr>

<tr>
<td align="left">Date </td>
<td><?php echo $row["mdate"]; ?></td>
</tr>
<tr>
<td align="left">Name:</td>
<td><?php echo $row["name"]; ?></td>
</tr>
<tr>
<td align="left">DOB </td>
<td><?php echo $row["dob"]; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><?php echo $row["address"]; ?></td>
</tr>
<tr>
<td>City:</td>
<td><?php echo $row["city"]; ?></td>
</tr>
<tr>
<td>State:</td>
<td><?php echo $row["state"]; ?></td>
</tr>
<tr>
<td>Country:</td>
<td><?php echo $row["country"]; ?></td>
</tr>
<tr>
<td>Pin:</td>
<td><?php echo $row["pin"]; ?></td>
</tr>
<tr>
<td>Phone No:</td>
<td><?php echo $row["phno"]; ?></td>
</tr>
<tr>
<td height="23">Amount:</td>
<td><?php echo $row["amount"]; ?></td>
</tr>
<tr>
<td height="28" colspan="2" align="center" id="prints"><input name="Button" type="button" class="button" id="Submit" onclick="window.location='employee_members.php';" value="Back" />
<input type="button" name="print" onclick="javascript:hides();" value="Print" /></td>
</tr>
</table></td>
</tr>
<tr>
<td height="23" colspan="2" id="foot"><?php include("../Insert Edit Delete pagination/include/footer.php");?></td>
</tr>
</table>
<?php
$i++;
}
?>
</form>
</body>
</html>

Output

PHP1.jpg

Inserting 1st record


PHP2.jpg

After inserting 10 records

PHP3.jpg


Edit employee

PHP4.jpg

Conclusion

So here we learn how to insert, edit, update and delete records from the database with pagination using PHP.

Article Extensions
Contents added by Husain Ahmed on Oct 10, 2012
COMMENT USING

Trending up