PHP - update MySql records

the mysql update statement is used to update existing data in can be used to change column values of a single row, group of rows or all rows in a tables.

mysql update syntax

       update       table_name1, table_name2, ...
       set            column_name1  =  expression_value,
                        column_name2  =  expression_value, ...
       where        condition ;                 

note : the php use mysqli_query() function to execute the update statement and send query to a mysql server.

the following example update data in 'users' table:

          $host = "localhost";
          $user_data = "leptop";
          $password_data = "12st";
          $dbname_data = "harddisk";               
     //":-:mysqli procedural style use to connect mysql database server"
 $connection_object = mysqli_connect( $host, $user_data, $password_data,

  if( $connection_object ){ echo  "<h6>'- able to connect to database -'<h6>";
                 }else {              
  echo  "<h6>connection failure  error --:- ". mysqli_connect_error() ."<h6>"; 
  $update = "update    users  set firstname='sandeep kumar'  salary=200000
                                                                 where salary =95492 ";        
mysqli_query( $connection_object, $update);

first the users table look like:


after executes the above php script the 'users' table look like:

sandeep kumarsing200000