Latest web development tutorials

PHP MySQL Update

UPDATE statement is used to modify the data in a database table.

Data updated in the database

UPDATE statement to update the database tables already exist in the record.


UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Note: Please note that the WHERE clause in the UPDATE syntax.WHERE clause specifies which records need to be updated. If you want to omit the WHERE clause, all records will be updated!

To learn more about SQL knowledge, please visit our SQL tutorial .

To get PHP to execute the statement above we must use mysqli_query () function. This function is used to send a query or command MySQL connection.


In the previous section of this tutorial, we have created a directory named "Persons" table, as follows:

FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33

The following example updates "Persons" some of the data table:

// 检测连接
if (mysqli_connect_errno())
	echo "连接失败: " . mysqli_connect_error();

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");


After this update, "Persons" table is as follows:

FirstName LastName Age
Peter Griffin 36
Glenn Quagmire 33