Php updating database

6854933580_2c8b688306_z

Result sets listed in this article (except for amending values section) have been generated in that way and by executing SELECT statements (SELECT * FROM `employee`) in command-line.Following is how to update the salary of an employee whose ID is 3.Kevin also covers the basic CRUD routines for updating a database, debugging techniques, and usable user interfaces.Along the way, he provides practical advice, offers examples of best practices, and demonstrates refactoring techniques to improve existing code.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).Using this you can then create the update script, which will actually have two sections to it.

By using the $id variable you output links which would pass the correct ID to the script so that it can update the database.------------ ----------- -------- ------------------------ | first_name | last_name | salary | notes | ------------ ----------- -------- ------------------------ | Robin | Jackman | 5700 | Salary was incremented | | Taylor | Edward | 7200 | NULL | | Vivian | Dickens | 6000 | NULL | | Harry | Clifford | 6800 | NULL | | Eliza | Clifford | 4750 | NULL | | Nancy | Newman | 5100 | NULL | | Melinda | Clifford | 8500 | NULL | | Harley | Gilbert | 8000 | NULL | ------------ ----------- -------- ------------------------ If the column type is numeric, you can use arithmetic operators ( , -, * and /) directly and if it is string, you have to use string functions like CONCAT_WS() and CONCAT().My SQL doesn't have a guaranteed order for updates.SQL commands for creating the table, inserting data and, truncating are available here.We recommend truncating the table and re-entering data after each example so that you can identify the change clearly (by comparing with original table shown above).---- ------------ ----------- ------------------------ -------- ------- | id | first_name | last_name | job_title | salary | notes | ---- ------------ ----------- ------------------------ -------- ------- | 1 | Robin | Jackman | Software Engineer | 5500 | NULL | | 2 | Taylor | Edward | Software Architect | 7200 | NULL | | 3 | Vivian | Dickens | Database Administrator | 6000 | NULL | | 4 | Harry | Clifford | Database Administrator | 6800 | NULL | | 5 | Eliza | Clifford | Software Engineer | 4750 | NULL | | 6 | Nancy | Newman | Software Engineer | 5100 | NULL | | 8 | Melinda | Clifford | Project Manager | 8500 | NULL | | 9 | Harley | Gilbert | Software Architect | 8000 | NULL | ---- ------------ ----------- ------------------------ -------- ------- Following PHP script shows how to use an update statement in PHP.

You must have an account to comment. Please register or login here!