Using this you can then create the update script, which will actually have two sections to it.The first part of the update script uses the single record selection from last week but adds a little HTML to it to make it more useful.First of all, we connect to the database and select the appropriate record.
WARNING: php version 5.2.6, as described later in this document is obsolete and prone to security issues.
Please consider either upgrading to php53 as included in Cent OS 5.6 or use the IUS Community Repo This guide describes how to upgrade the standard PHP 5.1.x packages in Cent OS 5.x 32-bit to the current development versions 5.2.x.
These instructions were created using Cent OS 5.3 32-bit and with the following PHP packages installed: As long as you're using the standard PHP packages on your Cent OS server you won't need to do anything extra.
So far you have learnt how to put information into your My SQL database, view the information in it and select which information you would like to view.
In this part I will show you how to do the two final actions, updating your database and deleting records from it.
Last week I explained how to create a link for each record to point to your update script.By using the $id variable you output links which would pass the correct ID to the script so that it can update the database.This makes it much more effective for an update script.$query = "UPDATE contacts SET first = '$ud_first', last = '$ud_last', phone = '$ud_phone', mobile = '$ud_mobile', fax = '$ud_fax', email = '$ud_email', web = '$ud_web' WHERE id = '$ud_id'"; This query tells the database to update the contacts table where the ID is the same as the value stored in $ud_id (which as you can see from the form on the previous page was set as the id of the record we are updating) and to set the following fields to the specified values (which were set using the form on the previous page).This query could then be integrated into a simple script: $ud_id=$_POST['ud_id']; $ud_first=$_POST['ud_first']; $ud_last=$_POST['ud_last']; $ud_phone=$_POST['ud_phone']; $ud_mobile=$_POST['ud_mobile']; $ud_fax=$_POST['ud_fax']; $ud_email=$_POST['ud_email']; $ud_web=$_POST['ud_web']; $username="username"; $password="password"; $database="your_database"; mysql_connect(localhost,$username,$password); $query="UPDATE contacts SET first='$ud_first', last='$ud_last', phone='$ud_phone', mobile='$ud_mobile', fax='$ud_fax', email='$ud_email', web='$ud_web' WHERE id='$ud_id'"; mysql_query($query); echo "Record Updated"; mysql_close(); At this time it seems appropriate to mention another use of loops with a database.As well as using a loop to get information from a database as we have before, you can also use loops to execute queries.