Update Data in MySQL Using PHP

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

how to fetch and update data from database in php

There are the Following The simple About dynamic update query in php Full Information With Example and source code.

As I will cover this Post with live Working example to develop delete query in php, so the php update sql database from form is used for this example is following below.

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

In the below example we update the worker data from MySQL database.

we used 2 file for update data

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

Step 1: connecting database

To connecting database.

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

Step 2: retrieve data from database

TO retrieve / fetch data from mysql database with a update option.

include_once 'dbConfig.php';
$result = mysqli_query($conn,"SELECT * FROM worker");
<!DOCTYPE html>
<link rel="stylesheet" href="style.css">
<title>Delete worker data</title>
<td>worker Id</td>
<td>Profile Name</td>
<td>Real Name</td>
<td>Email id</td>
while($data = mysqli_fetch_array($result)) {
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td><?php echo $data["memberid"]; ?></td>
<td><?php echo $data["profile_nm"]; ?></td>
<td><?php echo $data["real_nm"]; ?></td>
<td><?php echo $data["full_address"]; ?></td>
<td><?php echo $data["email"]; ?></td>
<td><a href="update-process.php?memberid=<?php echo $data["memberid"]; ?>">Update</a></td>

Step 3: update data MySql from database in PHP

TO update data from database.

include_once 'dbConfig.php';
if(count($_POST)>0) {
mysqli_query($conn,"UPDATE worker set memberid='" . $_POST['memberid'] . "', profile_nm='" . $_POST['profile_nm'] . "', real_nm='" . $_POST['real_nm'] . "', full_address='" . $_POST['full_address'] . "' ,email='" . $_POST['email'] . "' WHERE memberid='" . $_POST['memberid'] . "'");
$message = "Record Modified Successfully";
$result = mysqli_query($conn,"SELECT * FROM worker WHERE memberid='" . $_GET['memberid'] . "'");
$data= mysqli_fetch_array($result);
<title>Update worker Data</title>
<form name="frmmember" method="post" action="">
<div><?php if(isset($message)) { echo $message; } ?>
<div style="padding-bottom:5px;">
<a href="retrieve.php">worker List</a>
membername: <br>
<input type="hidden" name="memberid" class="txtField" value="<?php echo $data['memberid']; ?>">
<input type="text" name="memberid"  value="<?php echo $data['memberid']; ?>">
First Name: <br>
<input type="text" name="profile_nm" class="txtField" value="<?php echo $data['profile_nm']; ?>">
Last Name :<br>
<input type="text" name="real_nm" class="txtField" value="<?php echo $data['real_nm']; ?>">
<input type="text" name="full_address" class="txtField" value="<?php echo $data['full_address']; ?>">
<input type="text" name="email" class="txtField" value="<?php echo $data['email']; ?>">
<input type="submit" name="submit" value="Submit" class="buttom">



You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about update query in php form.
I would like to have feedback on my infinityknow.com 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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   jquery multiple Image Upload with preview and Delete using PHP
  2.   PHP MySQL CRUD Create, Insert, Update and Delete operations
  3.   laravel Redirect jQuery ajax success
  4.   WooCommerce Get Product Reviews
  5.   Laravel Define Global constants Config variables value
  6.   Laravel Image Upload Validation Tutorial
  7.   Laravel If Else and Switch Case
  8.   How to use multiple databases in Laravel
  9.   PHP MySQL Dynamic SQL Insert Query
  10.   PHP MySQLi Insert Update Delete Query Builder