Update Records in MySQL table using PHPMyAdmin


Step 1: Select the name of the table from database and click on Browse  link it will display all the records from the table as shown below:

Update Record

Step 2: Select the record from the list and click on button as shown below:

Update Record

Step 3: As you click on button it will display information of the selected record in the textbox as shown below:

Update Record

Step 4: Modify the record and click on GO button to save the record. It will update the record.

     

Update Records in MySQL table using PHP Script


In order to edit records in the database table using PHP script write following script in the EditRecord.php file as shown below:

<html>
<head>
<Title> Edit Record</title>
</head>
<body>
<table border="1" >
<tr>
<th>Customer Code</th>
<th>Customer Name</th>
<th>Customer City</th>
</tr>
<?php
// Establish Connection with Database
$con = mysql_connect("localhost","root");
// Select Database
mysql_select_db("DBDEMO", $con);
// Specify the query to execute
$sql = "select * from Customer_Master";
// Execute query
$result = mysql_query($sql,$con);
// Loop through each records
while($row = mysql_fetch_array($result))
{
$Code=$row['CustomerCode'];
$Name=$row['CustomerName'];
$City=$row['City'];
?>
<tr>
<td><?php echo $Code;?></td>
<td><?php echo $Name;?></td>
<td><?php echo $City;?></td>
<td><a href="UpdateRecord.php?CustomerCode=<?php echo $Code;      ?>">Edit</a></td>
</tr>
<?php
}
// Close the connection
mysql_close ($con);
?>
</body>

It will display records from database table along with Edit hyperlink as shown below:

Update Record

When user click on Edit hyperlink it will redirected to UpdateRecord.php file which display the information of selected customer in Textboxes. Write following script in UpdateRecord.php file to do so.

<html>
<head>
<Title> Update Record</title>
</head>
<body>
<?php
$Code=$_GET['CustomerCode'];
// Establish Connection with Database
$con = mysql_connect("localhost","root");
// Select Database
mysql_select_db("DBDEMO", $con);
// Specify the query to execute
$sql = "select * from Customer_Master where CustomerCode=".$Code."";
// Execute query
$result = mysql_query($sql,$con);
// Loop through each records
while($row = mysql_fetch_array($result))
{
$Code=$row['CustomerCode'];
$Name=$row['CustomerName'];
$City=$row['City'];
}
?>
<form Method="POST" Action="Update.php">
<table border="1">
<tr>
<td>Customer Code:</td>
<td> <input type="text" Name="Code" value="<?php echo $Code;?>" /></td>
</tr>
<tr>
<td>Customer Name:</td>
<td> <input type="text" Name="Name" value="<?php echo $Name;?>" /></td>
</tr>
<tr>
<td>Customer City:</td>
<td> <input type="text" Name="City" value="<?php echo $City;?>" /></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" Name="submit" value="submit" /></td>
</tr>
</table>
</form>
<?php
// Close the connection
mysql_close($con);
?>
</table>
</body>

In the above script CustomerCode is retrieved from URL and the information of that Customer is displayed in textbox as shown below:

Update Record

After editing the information of selected customer in textbox when user click on submit button in order to edit that information in database table write following code in the Update.php file.

<?php
$Code = $_POST['Code'];
$Name=$_POST['Name'];
$City=$_POST['City'];
echo $Code;
// Establish Connection with MYSQL
$con = mysql_connect("localhost","root");
// Select Database
mysql_select_db("DBDEMO", $con);
// Specify the query to Update Record
$sql = "Update Customer_Master set CustomerName='".$Name."',City='".$City."' where CustomerCode=".$Code."";
// Execute query
mysql_query($sql,$con);
// Close The Connection
mysql_close($con);
echo "Record Updated Succesfully";
?>

Download Projects


Download Programs