MySQL UPDATE statement is used to change or update the existing records in a database table. MySQL UPDATE statement is usually used in conjugation with the WHERE clause to apply the changes to only those records that matches specific criteria.

UPDATE Records Conditions

Synrax

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

Example

<?php
     // Create connection        
    $link = mysqli_connect("localhost", "root", "", "demo");

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

    // Attempt update query execution
    $sql = "UPDATE user SET email='abc@gmail.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);
    }
 
?>

UPDATE All Data

Synrax

UPDATE table_name SET column1=value, column2=value2,... 

Example

<?php
     // Create connection        
    $link = mysqli_connect("localhost", "root", "", "demo");

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

    // Attempt update query execution
    $sql = "UPDATE user SET email='abc@gmail.com'";
    if(mysqli_query($link, $sql)){
        echo "Records were updated successfully.";
    } else {
        echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }
 
?>