---
title: "Updating and Deleting Record in MySQL Database Table using PHP"  
description: "Updating Record:UPDATE statement is used for update existing records in MySQL database table.Syntax:UPDATE table_name SET column_name1 = value1, colum"  
author: "Anonymous User"  
published: 2011-09-21  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/738/updating-and-deleting-record-in-mysql-database-table-using-php  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# Updating and Deleting Record in MySQL Database Table using PHP

##### Updating Record:

UPDATE statement is used for update existing records in MySQL database table.

##### Syntax:

UPDATE table_name SET column_name1 = value1, column_name2 = value2,..... WHERE column_name = column_value

**Note:** WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated.

##### Example:

```
        <?php         // create connection         $con = mysql_connect("localhost", "root", "root");        // check connection is created or not         if(!$con)        {            die ("Conection not created. Please try again !");         }         // select database         mysql_select_db('tempdatabase',$con);           // update query         $qry ="Update tblTemp set EmailId = 'username@hostname.com' where id = 102";         // execute the queryand check updation         if(mysql_query($qry))         {             echo 'Data updated successfully';         }         else         {             echo   'Updation failed' ;          }    ?>
```

##### Output:

![Updating and Deleting Record in MySQL Database Table using PHP](https://www.mindstick.com/mindstickarticle/727876e1-cdac-4a2d-afa5-311a9fafac35/images/af7bfd8c-7db6-4019-9d9e-e6d62936ce7c.png)

##### Deleting Record:

DELETE FROM statement is used to delete records from database table.

##### Syntax:

DELETE FROM tbl_Name WHERE column_name= value

##### Example:

Look at the following ‘tblTemp’ table.

![Updating and Deleting Record in MySQL Database Table using PHP](https://www.mindstick.com/mindstickarticle/727876e1-cdac-4a2d-afa5-311a9fafac35/images/31c083da-5498-4d7d-b87a-ca91670c4c78.png)

Now we want to delete record from ‘tblTemp’ table where id is103. Let’s have an example to performing this action.

```
<?php         // create connection         $con = mysql_connect("localhost", "root", "root");        // check connection is created or not         if(!$con)        {            die ("Conection not created. Please try again !");         }         // select database         mysql_select_db('tempdatabase',$con);           // Delete query         $qry ="Delete from tblTemp where id =103";         // execute the queryand check updation         if(mysql_query($qry))         {             echo 'Record deleted successfully';         }         else         {             echo   'Record could not deleted.' ;          }    ?>
```

**Note:** WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted from given table.

##### Output:

![Updating and Deleting Record in MySQL Database Table using PHP](https://www.mindstick.com/mindstickarticle/727876e1-cdac-4a2d-afa5-311a9fafac35/images/a660b986-4fba-47b7-b8ae-8b397611a014.png)

Now look ‘tblTemp’ table records.

![Updating and Deleting Record in MySQL Database Table using PHP](https://www.mindstick.com/mindstickarticle/727876e1-cdac-4a2d-afa5-311a9fafac35/images/fa474364-9d8f-4967-957f-bc2a1d2eebb7.png)

\

---

Original Source: https://www.mindstick.com/articles/738/updating-and-deleting-record-in-mysql-database-table-using-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
