The basic syntax of the MySQL UPDATE query: 

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

  • First, connect to the database 
  • check the connection
  • Updating persons email where id is 1 from the persons table 


#example.php

<?php

//connect to the db
$link = mysqli_connect("localhost", "root", "", "demo");

// Check connection
if ($link === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

//  update query execution
$sql = "UPDATE persons SET email='test@mail.com' WHERE id=1";
if (mysqli_query($link, $sql)) {
    echo "Records were updated successfully.";
} else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>