how to update data from database in mysql php?

Today, We want to share with you update query in mysql php.In this post we will show you update multiple columns query in php, hear for dynamic update query in php we will give you demo and example for implement.In this post, we will learn about PHP crud Mysqli Select Insert Update and Delete query with an example.

how to fetch and update data from database in php?

The update mysql database keyword is basically used to modify/change or edit the existing some records in the database table.
PHP MySQL Update Query : Syntax

UPDATE table_name SET column1=value1,column2=value2... WHERE column = value 

simple you can run or execure on your server following full source code to understand update operation. You need to provide an players ID to update an players salary.

Also Read This ๐Ÿ‘‰   .htaccess Redirect old domain to new domain with URL match


      <title>Update a Record in MySQL Database</title>
         if(isset($_POST['update'])) {
            $dbhost = 'yourhostname';
            $dbuser = 'mainusername';
            $dbpass = 'DSF7#$57f7ff';
            $conn = mysql_connect($dbhost, $dbuser, $dbpass);
            if(! $conn ) {
               die('Could not connect: ' . mysql_error());
            $player_id = $_POST['player_id'];
            $player_salary = $_POST['player_salary'];
            $sql = "UPDATE players ". "SET player_salary = $player_salary ". 
               "WHERE player_id = $player_id" ;
            $retval = mysql_query( $sql, $conn );
            if(! $retval ) {
               die('Could not update data: ' . mysql_error());
            echo "Updated data successfully\n";
         }else {
               <form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border =" 0" cellspacing = "1" 
                     cellpadding = "2">
                        <td width = "100">Players ID</td>
                        <td><input name = "player_id" type = "text" 
                           id = "player_id"></td>
                        <td width = "100">Players Salary</td>
                        <td><input name = "player_salary" type = "text" 
                           id = "player_salary"></td>
                        <td width = "100"> </td>
                        <td> </td>
                        <td width = "100"> </td>
                           <input name = "update" type = "submit" 
                              id = "update" value = "Update">

This example updates some data in the “playerInfo” table

//connect database 
$con=mysqli_connect("localhost","root","","Players") or die(mysqli_error());

//update values of playerInfo table
$data="UPDATE playerInfo SET name='rohitsharma',mobile=98256062*** WHERE email='[email protected]'";

I hope you get an idea about how to update data in php using form mysqli.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.