How to update query in PHP MySQL?

Today, We want to share with you update query in mysql.In this post we will show you update multiple columns in mysql, hear for how to update data in php using form mysqli we will give you demo and example for implement.In this post, we will learn about Bootstrap Toggle switch with ajax update to mysql in PHP with an example.

Update Data in MySQL Using PHP

To update a data that already exist in the mysql database, simple UPDATE statement is used.

Read Also:  Drag And Drop Multiple File Uploading using DropzoneJS and PHP Example

In the below easy to best example we update the players data from MySQL database.

we used 2 file for update data

  • database.php– To connecting database.
  • update.php– TO retrieve data from database with a update option.
  • update-players.php– TO update data from database.


 die('Could not Connect My Sql:' .mysql_error());


include_once 'database.php';
$result = mysqli_query($conn,"SELECT * FROM players");
<!DOCTYPE html>
<link rel="stylesheet" href="style.css">
<title>Delete players data</title>
<td>Players Id</td>
<td>Player Name</td>
<td>Player Ranking</td>
<td>Player City</td>
<td>Player Email id</td>
while($row = mysqli_fetch_array($result)) {
<tr class="<?php if(isset($dynamic_add_class_css)) echo $dynamic_add_class_css;?>">
<td><?php echo $row["playerid"]; ?></td>
<td><?php echo $row["playername"]; ?></td>
<td><?php echo $row["player_ranking"]; ?></td>
<td><?php echo $row["player_city"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><a href="update-players.php?playerid=<?php echo $row["playerid"]; ?>">Update</a></td>


include_once 'database.php';
if(count($_POST)>0) {
mysqli_query($conn,"UPDATE players set playerid='" . $_POST['playerid'] . "', playername='" . $_POST['playername'] . "', player_ranking='" . $_POST['player_ranking'] . "', player_city='" . $_POST['player_city'] . "' ,email='" . $_POST['email'] . "' WHERE playerid='" . $_POST['playerid'] . "'");
$message = "Record Modified Successfully";
$result = mysqli_query($conn,"SELECT * FROM players WHERE playerid='" . $_GET['playerid'] . "'");
$row= mysqli_fetch_array($result);
<title>Update Players Data</title>
<form name="frmUser" method="post" action="">
<div><?php if(isset($message)) { echo $message; } ?>
<div style="padding-bottom:5px;">
<a href="retrieve.php">Players List</a>
Username: <br>
<input type="hidden" name="playerid" class="txtPlayerinfo" value="<?php echo $row['playerid']; ?>">
<input type="text" name="playerid"  value="<?php echo $row['playerid']; ?>">
First Name: <br>
<input type="text" name="playername" class="txtPlayerinfo" value="<?php echo $row['playername']; ?>">
Last Name :<br>
<input type="text" name="player_ranking" class="txtPlayerinfo" value="<?php echo $row['player_ranking']; ?>">
<input type="text" name="player_city" class="txtPlayerinfo" value="<?php echo $row['player_city']; ?>">
<input type="text" name="email" class="txtPlayerinfo" value="<?php echo $row['email']; ?>">
<input type="submit" name="submit" value="Submit" class="buttom">


I hope you get an idea about dynamic update query in php.
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.

Read Also:  How to update statement in mysql using PHP?

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Mysql update query statement with example
  2. Read Also:  PHP Auto post Blogger Scripts Example
  3. Read Also:  how to install PHP Accelerator in Xampp
  4. Read Also:  jQuery AJAX file Image upload PHP Example
  5. Read Also:  MySQL Multicolumn UPDATE JOIN subquery
  6. Read Also:  PHP curl Http authentication header from Client
  7. Read Also:  Session Management in CodeIgniter with PHP
  8. Read Also:  How to Insert Data Into MySQL Database Table Using PHP?
  9. Read Also:  how to delete a row in mysql using php?
  10. Read Also:  how to create sql database file in mysql?