How to update and delete data in php?

Delete Data From a MySQL Table Using MySQLi and PDO

The DELETE statement is used to delete records from a table:

DELETE FROM table_name
WHERE some_column = some_value

Notice the WHERE clause in the DELETE syntax: The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!

To learn more about SQL, please visit our SQL tutorial.

Let's look at the "MyGuests" table:

idfirstnamelastnameemailreg_date
1 John Doe 2014-10-22 14:26:15
2 Mary Moe 2014-10-23 10:22:30
3 Julie Dooley 2014-10-26 10:48:23

The following examples delete the record with id=3 in the "MyGuests" table:

Example [MySQLi Object-oriented]


Example [MySQLi Procedural]


Example [PDO]


After the record is deleted, the table will look like this:

idfirstnamelastnameemailreg_date
1 John Doe 2014-10-22 14:26:15
2 Mary Moe 2014-10-23 10:22:30



How to insert update delete record using php and mysql. In this tutorial we will show you step by step how to insert update delete record using php and mysql.

As well as you can use this insert update delete in php with source code to personally and professinally.

Use the following steps to select insert update delete record using PHP and MySQL:

  • DB.PHP – Connecting Database
  • Insert.PHP – Insert Records Into MySQL DB
  • Select.php – Select Record From MySQL DB
  • Update.php – Update Record Into MySQL DB
  • Delete.php – Delete Record From MySQL DB

In this example post will use the following SQL query to Select, insert, update, and delete records from MySQL Database Table in PHP.

  • In starting, we will create MySQL database connection file in PHP.
    • Will use mysqli_connect[] function to connecting database with PHP.
  • Then will use “SELECT FROM” SQL query to select a record from the MySQL database.
  • Then “INSERT INTO” SQL query to insert record into the MySQL database.
  • After that, “Update” SQL query to update the record into the MySQL database.
  • Finally, “DELETE From” SQL query to delete record into MySQL database.
  • As well as will use mysqli_query[] function for run sql queries.

1 – DB.PHP – Connecting Database

First of all, Create db.php file to connecting mysql database with PHP:


2 – Insert.PHP – Insert Records Into MySQL DB

Then, Create a new file named insert.php and add the following code into insert.php:

Chủ Đề