Updating and Deleting a database record is a necessary and easy thing to do for any web developer and in any web development course you will find a version or two of them  and here we will be looking at MySQL and PHP version which is useful if you are making changes or building any PHP based open source software like  WordPress plugin or even customizing a Prestashop or Zen-Cart.

Here are the steps to do it:

Make a page to display the records in the database

Make a connection to the database using PHP

Display all records in the database(or as many as you like to put 20 or 50 records per page or any other number that you need) and add a link for Edit this Entry and Delete this Entry

for Edit entry link to another page that has a form this form will send the data to the same PHP page and then display the user data (or entry data) inside the fields in the form.

at the end of the page you will check to see if the “submit” button has been pressed by checking : isset($_POST[‘submit’])

if it is then update the entry using:

UPDATE table_name
SET column1=value, column2=value2,…
WHERE some_column=some_value

so what it means is change the data in column1 to value and data in column2 to value2 and so on in any entry in this database and in “table_name” table when “some_column” has the value of “some_value”. for some_value and some_column use the record id  and pass it to this page using the hidden field <input type=”hidden” value=”some_value” />

use mysql_query to execute it (the mysql code is inside “”).

and make an error check so if it is not executed or there was an error to display an error message for you.

for deleting the entry use :

DELETE FROM table_name
WHERE some_column = some_value

Simple right?