Updating a database record with PHP

We explain how to modify or update an existing record in a database table, with PHP. That is, make an update for a record in a table, from PHP.

To show how a record present in our database is updated, we are going to do it from a slightly more complex case so that we begin to familiarize ourselves with these operations. We will make a couple of scripts that allow us to change the phone number of the different people present in our database. The name of these people, as well as the new telephone number, will be collected through a form.

The form file will this time be a PHP script in which we will make a call to our database to build a drop-down menu where all the names appear. The thing would be like this:

Update1.php

Update a record

Name
‘; //We create the SQL statement and execute it $sSQL=”Select name From customers Order By name”; $result=mysql_query($sSQL); echo ‘
Phone

The way of operating to build the drop-down menu is the same as to display the table. Again we use a while loop in combination with the mysql_fetch_array function which allows us to display each of the options.

The update script will be very similar to the insert:

Update2.php

Updated Record

As you have seen, the UPDATE operation is not very complex. However, to consolidate this knowledge we recommend seeing the .

Loading Facebook Comments ...
Loading Disqus Comments ...