Update a MySql record with PHP

You can also update a record in your table. Not surprisingly, the word UPDATE is used for this. Here’s an example:

$SQL = "UPDATE AddressBook SET email = 'new_email_address' WHERE First_Name = 'Bill' AND Surname = 'Gates'";

After the word UPDATE, you need the name of the table you want to update. Then you need another Keyword: SET. After the word SET, you type the name of the Column you want to change. In the SQL above, we’re changing the email column. But notice the WHERE clause. We’ve specified that the record to change should have the First_Name of Bill and the Surname of Gates.

You can also update an entire column, and change all the values:

UPDATE AddressBook SET Surname = LOWER(Surname);

Again, we’ve specified that the AddressBook table should be updated. We’ve SET the column name as Surname. After an equals sign, we’ve used the inbuild SQL function LOWER( ). This changes a value to lower case letters. In between the round brackets of the function, we’ve typed the column name again. This will ensure that all the text in the Surname column gets changed to lower case.