PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Updating (Web hosting ecommerce)

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Updating records An update page needs to perform two separate processes, as follows: 1. Retrieve the selected record and display it ready for editing 2. Update the edited record in the database The first stage uses the primary key passed in the URL query string. So far, you have used SELECT to retrieve all records or a range of records (using LIMIT). To retrieve a specific record identified by its primary key, you add a WHERE clause to the end of the SELECT query like this: SELECT * FROM table_name WHERE primary_key_column = primary_key Whereas PHP uses two equal signs (==) to test for equality, MySQL uses only one (=). Don t get the two mixed up. After you have edited the record in the update page, you submit the form and pass all the details to an UPDATE command. The basic syntax of the SQL UPDATE command looks like this: UPDATE table_name SET column_name = value, column_name = value WHERE condition The condition when updating a specific record is the primary key. So, when updating article_id 2 in the journal table, the basic UPDATE query looks like this: UPDATE journal SET title = value, article = value WHERE article_id = 2 Although the basic principle is the same for each method of connecting to MySQL, the code differs sufficiently to warrant separate instructions. PHP Solution 13-5: Updating a record with the original MySQL extension Use journal_update01.php fromthe download files. The code for the first stage of the update process is in journal_update_mysql01php, and the final code is in journal_update_mysql02.php. 1. The first stage involves retrieving the details of the record that you want to update. Since the primary key is passed through the query string, you need to extract it from the $_GET array and make sure that it s safe to use before incorporating it into your SQL query. Put the following code above the DOCTYPE declaration: Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Leave a Reply