In this example, update the existing record in the mysql database table using UPDATE statement.
PHP MySQL UPDATE Statement Example:
In this example, update the existing record in the mysql database table using UPDATE statement.
Syntax:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ $db_name = "php_mysql"; mysql_select_db($db_name, $connection); $update_sql = "UPDATE user SET user_name='Brijesh', user_email='brijesh@gmail.com', user_address='Delhi' WHERE user_id=1;"; mysql_query($update_sql, $connection); echo "Last update record has id : 1."; } mysql_close($connection); ?>
Output:
Before running this example the database table have record as:
After running this example the browser output is:
Last update record has id : 1.
And the database table record is:
[ 0 ] Comments