Edit data in database


This is file use for edit data in database . the file name (edit.php)
<head>
<meta>
<title>edit</title>
</head>

<body>
<?php
include(“db.php”);
$id=$_REQUEST[‘id’];
echo $id;
$query=”select * from record where id=$id”;
$row=mysql_query($query);
while($run=mysql_fetch_array($row))
{
?>
<h1 align=”center”>Employee Record</h1>
<form method=”post”>
<table border=”1″ align=”center” bgcolor=”#006699″>
<tr>
<td>firstname</td>
<td> <input type=”text” name=”firstname”  value=”<?php echo $run[‘firstname’];?>”/> </td>
</tr>
<tr>
<td>lastname</td>
<td> <input type=”text” name=”lastname”  value=”<?php echo $run[‘lastname’];?>”/> </td>
</tr>
<tr>
<td>fathername</td>
<td> <input type=”text” name=”fathername”  value=”<?php echo $run[‘fathername’];?>”/> </td>
</tr>
<tr>

<td>dob</td>
<td> <select name=”dob”/>
<option>day</option>
<?php
for($day=1;$day<=31;$day++)
{
echo “<option>” .$day. “</option>”;
}
?>
</select>
<select>
<option>month</option>
<?php
$month=array(‘jan’,’feb’,’mar’,’april’,’may’,’june’,’july’,’aug’,’sep’,’oct’,’nov’,’dec’);
foreach($month as $a)
{
echo “<option>” .$a.”</option>”;
}
?>
</select>
<select>
<option>year</option>
<?php
for($year=1985;$year<=2013;$year++)
{
echo “<option>” .$year . “</option>”;
}
?>
</select>
</td>
</tr>
<tr>
<td>contactno</td>
<td> <input type=”text” name=”contactno”  value=”<?php echo $run[‘contactno’];?>”/></td>
</tr>
<tr>
<td>address</td>
<td> <input type=”text” name=”address”  value=”<?php echo $run[‘address’];?>”/></td>
</tr>
<tr>
<td>agreementsiqn</td>
<td> <input type=”text” name=”agreementsign”  value=”<?php echo $run[‘agreementsiqn’];?>”/></td>
</tr>
<tr>
<td>email</td>
<td> <input type=”text” name=”email”  value=”<?php echo $run[’email’];?>”/></td>
</tr>
<tr>
<td>password</td>
<td> <input type=”password” name=”password”  value=”<?php echo $run[‘password’];?>”/></td>
</tr>
<tr>
<td>gender</td>
<td> <input type=”radio” name=”gender” value=”m” />male
<input type=”radio” name=”gender” value=”f” />female</td>
</tr>
<tr>
<td colspan=”2″ align=”center”> <input type=”submit” name=”submit” value=”submit” /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST[‘submit’]))
{
include(‘db.php’);
$firstname=$_POST[‘firstname’];
$lastname=$_POST[‘lastname’];
$fathername=$_POST[‘fathername’];
$dob=$_POST[‘dob’];
$contactno=$_POST[‘contactno’];
$address=$_POST[‘address’];
$agreementsign=$_POST[‘agreementsign’];
$email=$_POST[’email’];
$password=$_POST[‘password’];
$gender=$_POST[‘gender’];
$update=”update record set firstname=’$firstname’,lastname=’$lastname’,fathername=’$fathername’,dob=’$dob’,contactno=’$contactno’,address=’$address’,agreementsign=’$agreementsign’,email=’$email’,password=’$password’,gender=’$gender’ where id=$id”;
if(!mysql_query($update))
{
echo “data not created”.mysql_error();
}
else header(‘location:usingquery.php’);
}

?>

<?php }
?>

</body>
</html>

html form submit in database and select data from database


<h4> file name for thes use file (usingquery.php)</h4>
<head>
<meta>
<title>Employee Record’s</title>
<head>

<script type=”text/javascript”>
function showconfirm()
{
return confirm(“Are you sure?”);
}
</script>
</head>

<body>
<h1 align=”center”>Employee Record</h1>
<form method=”post”>
<table border=”1″ align=”center” bgcolor=”#006699″>
<tr>
<td>firstname</td>
<td> <input type=”text” name=”firstname” /></td>
</tr>
<tr>
<td>lastname</td>
<td> <input type=”text” name=”lastname” /></td>
</tr>
<tr>
<td>fathername</td>
<td> <input type=”text” name=”fathername” /></td>
</tr>
<tr>
<td>dob</td>
<td> <select name=”dob”/>
<option>day</option>
<?php
for($day=1;$day<=31;$day++)
{
echo “<option>” .$day. “</option>”;
}
?>
</select>
<select>
<option>month</option>
<?php
$month=array(‘jan’,’feb’,’mar’,’april’,’may’,’june’,’july’,’aug’,’sep’,’oct’,’nov’,’dec’);
foreach($month as $a)
{
echo “<option>” .$a.”</option>”;
}
?>
</select>
<select>
<option>year</option>
<?php
for($year=1985;$year<=2013;$year++)
{
echo “<option>” .$year . “</option>”;
}
?>
</select>

</td>
</tr>
<tr>
<td>contactno</td>
<td> <input type=”text” name=”contactno” /></td>
</tr>
<tr>
<td>address</td>
<td> <input type=”text” name=”address” /></td>
</tr>
<tr>
<td>agreementsign</td>
<td> <input type=”text” name=”agreementsign” /></td>
</tr>
<tr>
<td>email</td>
<td> <input type=”text” name=”email” /></td>
</tr>
<tr>
<td>password</td>
<td> <input type=”password” name=”password” /></td>
</tr>
<tr>
<td>gender</td>
<td> <input type=”radio” name=”gender” value=”m” />male
<input type=”radio” name=”gender” value=”f” />female</td>
</tr>
<tr>
<td colspan=”2″ align=”center”> <input type=”submit” name=”submit” value=”submit” /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST[‘submit’]))
{
include(‘db.php’);
$firstname=$_POST[‘firstname’];
$lastname=$_POST[‘lastname’];
$fathername=$_POST[‘fathername’];
$dob=$_POST[‘dob’];
$contactno=$_POST[‘contactno’];
$address=$_POST[‘address’];
$agreementsign=$_POST[‘agreementsign’];
$email=$_POST[’email’];
$password=$_POST[‘password’];
$gender=$_POST[‘gender’];
$query=”insert into record(`firstname` , `lastname` , `fathername` , `dob` , `contactno` , `address` , `agreementsign` , `email` , `password` ,`gender`)values(‘$firstname’,’$lastname’,’$fathername’,’$dob’,’$contactno’,’$address’,’$agreementsign’,’$email’,’$password’,’$gender’)”;
$result=mysql_query($query);
if(!$result)
{
echo “data not created successfully”. mysql_error();
}
else
{
echo “data created successfully”;
}
}
?>
<table border=”1″ align=”center” bgcolor=”#CCFF33″>
<tr>
<td>firstname</td>
<td>fathername</td>
<td>address</td>
<td>agreementsign</td>
<td colspan=”2″ align=”center”>action</td>
</tr>
<tr>

<?php
include(‘db.php’);
$scl=”select * from record”;
$result=mysql_query($scl);
while($fetch=mysql_fetch_array($result))
{
?>
<tr>
<td> <a href=”select.php?id=<?php echo $fetch[‘id’];?>”><?php echo  $fetch[‘firstname’]; ?></a></td>
<td> <?php echo $fetch[‘fathername’];?> </td>
<td> <?php echo $fetch[‘address’];?> </td>
<td> <?php echo $fetch[‘agreementsign’];?> </td>
<td> <a href=”edit.php?id=<?php echo $fetch[‘id’];?>”>edit</a></td> <td><a href=”delete.php?id=<?php echo $fetch[‘id’];?>” onclick=”return showconfirm();”>delete</a></td>
</tr>
<?php
}
?>

</body>
<html>

PHP


php code

How to use code for create,Insert,Delete and Edit Data

The explain point for create,Insert,Delete and Edit Data values in database…

STEP 1. connectivity database , file name (db.php)

<?php
$con=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“employee”);
?>

STEP 2.  Create  table  .

<?php

mysql_connect(“localhost”,”root”,””) or die (mysql_error());
mysql_select_db(“employee”) or die (mysql_error());

$sql=CREATE TABLE `record` (
`id` int(11) NOT NULL auto_increment,
`firstname` varchar(100) NOT NULL,
`lastname` varchar(100) NOT NULL,
`fathername` varchar(100) NOT NULL,
`dob` varchar(100) NOT NULL,
`contactno` varchar(100) NOT NULL,
`address` varchar(100) NOT NULL,
`agreementsign` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`gender` varchar(100) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

mysql_query(“$sql”);

?>