To update data currently in your database, you use the UPDATE command. You specify all the fields you want to change, and the values you want to change them to like this:
UPDATE usertable SET FirstName = 'Joe', Age = 30;
That statement will change all records in usertable so that they have the FirstName "Joe" and Age "30". We can filter the rows to be updated by using a WHERE clause, just like in SELECT. So, to change all people with FirstName "Joe" to FirstName "Peter", we would use this statement:
UPDATE usertable SET FirstName = 'Peter' WHERE FirstName = 'Joe';
It's quite easy, isn't it? UPDATE can also use the LIMIT clause, to allow you to only update the first n matching rows, but this is rarely used.
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!