PHP MySql UPDATE Query tutorial will explain you How to update data in MySQL database with PHP? with Examples. MySql UPDATE is the command used to modify existing table rows with new data values.

Update data using PHP MySql UPDATE Query

PHP MySql UPDATE Query is used to change or modify the existing values in a table. Update statement has the ability to update every single row in a database with the execution of only a single query.

 Syntax for PHP MySql UPDATE Query:

The update statement requires more caution: If used alone, it will modify ALL records with one command.

e.g. the following SQL statement, if put into a query, would set all firstnames to Fred:
UPDATE $tablename SET firstname = “Fred”

To set only Fred’s record to firstname = Fred, you must specify that it only applies to his record.

e.g. if the database contains a unique field called ‘id’ and the value for id in Fred’s record is 84:
UPDATE $tablename SET firstname = “Fred” WHERE id = 84

Example on PHP MySql UPDATE Query:

Here is the example where we update some data of row whose ID = 1.
We use a table containing the following fields:

  • ID – auto generated integer
  • FName – First Name, varchar
  • LName – Last Name, varchar
  • PHONE – Phone number, varchar

Consider this is a table before upadation:

ID First Name Last Name Phone Number
0 Kim Kad 8912543287
1 Jon Job 9634234976

Here is the PHP code to update record from above table:

Output of the above code:

ID First Name Last Name Phone Number
0 Kim Kad 8912543287
1 james martin 7857342197
Previous articlePHP MySql ORDER BY
Next articlePHP MySql Delete
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!