Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

PHP

Learn step by step



Editing Data

In editing the data, you can use the syntax as follow:
UPDATE name_table SET field1=new_value, field2=new_value, ...
WHERE condition1,condition2, ...

For example, we will try to edit one of the data from data_employees table: file: db.inc.php for connection database

<?
//file include for database connection
//db.inc.php
//database connection
mysql_connect("localhost","root","admin");

// database selection
mysql_select_db("employees");
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?
include"db.inc.php";//database connection
$order = "SELECT * FROM data_employees";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[name]</td>");
echo ("<td>$row[employees_number]</td>");
echo ("<td>$row[address]</td>");
echo ("<td><a href=\"edit_form.php?id=$row[employees_number]\">Edit</a></td></tr>");
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table>
<?
include "db.inc.php";//database connection
$order = "SELECT * FROM data_employees
where employees_number='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<? echo "$row[employees_number]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name"
size="20" value="<? echo "$row[name]"?>">
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" size="40"
value="<? echo "$row[address]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>

Form Edit Employee Data
Name
Address

EDIT DATA
Jai 001 India Edit
Pankj 002 India Edit
Ramesh 003 Hindustan Edit



Related Videos