I want to update the record in the table from web page . means i will click on update in from of row and it should redirect to update page and required field should get update .
here is the code for update
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>First web page</title>
</head>
<body>
<div id="wrapper">
<?php include('includes/header.php'); ?>
<?php include('includes/nav.php'); ?>
<div id="content">
<h3>Paragraph Element</h3>
<?php
function renderForm($id, $name, $email, $date,$mobile,$gender,$lang,$error)
{
?>
<form action="" method="post" enctype="multipart/form-data">
<table class="tbldata" align="center" border="1px solid black" style="background-color:!important" >
<tr id="bgcolor">
<td colspan="2" align="center" style="background-color: #CF3">Submit Employee Information</td>
</tr>
<tr id="bgcolor">
<td >Name</td>
<td class="back"><input type="text" name="name" value="<?php echo $name ?>"/></td>
</tr>
<tr id="bgcolor">
<td>E-mail</td>
<td class="back"><input type="text" name="email" value="<?php echo $email ?>" /></td>
</tr>
<tr id="bgcolor">
<td>DOB</td>
<td class="back"><input type="date" name="date" value="<?php echo $date ?>" /></td>
</tr>
<tr id="bgcolor">
<td>Mobile_No</td>
<td class="back"><input type="text" name="mobile" value="<?php echo $mobile ?>"/></td>
</tr>
<tr id="bgcolor">
<td>Gender</td>
<td class="back"><input id="bgcolor" type="radio" name="gender" value="<?php echo $gender ?>" checked="checked">M</input> <input type="radio" name="gender" value="<?php echo $gender ?>">F</input></td>
</tr>
<tr id="bgcolor">
<td>Language</td>
<td class="back"><select name="lang"><option value="<?php echo $lang ?>" >English</option>
<option value="<?php echo $data->lang ?>">Marathi</option>
<option value="<?php echo $data->lang ?>">Hindi</option> </select></td>
</tr>
<tr id="bgcolor">
<td>Photo</td>
<td class="back"><input type="file" name="file" value="<?php echo $file ?>" /></td> </tr>
<tr>
<td colspan="7"><input type="submit" value="Submit" name="update" /> <a href="dashboard.php" style="text-decoration:none" > <input type="button" value="Back"/></a> </td>
</tr>
</table>
</form>
<?php } ?>
</div>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("firstweb");
if (isset($_POST['update']))
{
if (is_numeric($_POST['id']))
{
$id = $_POST['id'];
$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
$date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
$mobile = mysql_real_escape_string(htmlspecialchars($_POST['mobile']));
$gender = mysql_real_escape_string(htmlspecialchars($_POST['gender']));
$lang = mysql_real_escape_string(htmlspecialchars($_POST['lang']));
if ($name == '' || $email == '' || date == '' || mobile == '' )
{
$error = 'ERROR: Please fill in all required fields!';
renderForm($id, $name, $email, $date,$mobile,$gender,$lang,$error);
}
else
{
mysql_query("UPDATE emp_data SET name='$name',email='$email',date='$date',mobile='$mobile',gender='$gender',lang='$lang',image='$image' where id='$id'")
or die(mysql_error());
header("Location: dashboard.php");
}
}
else
{
echo 'Error!';
}
}
else
{
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM emp_data WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$name = $row['name'];
$email = $row['email'];
$date = $row['date'];
$mobile = $row['mobile'];
$gender = $row['gender'];
$lang = $row['lang'];
renderForm($id, $name, $email, $date,$mobile,$gender,$lang,'');
}
else
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
<?php include('includes/sidebar.php'); ?>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
can anyone help to get it resolved??