Friends, you must know one thing that in any website, whether it is WordPress or HP, there is one thing which is very important, that is our operation, which means inserting any data in the database, fetching data from it, updating it, deleting it, are called operations.
When we retrieve the data from the database, we have created two (2) buttons in the actions column. One of them is the update button that acts as an anchor tag.
edit.php
<?php
global $wpdb;
$id = $_GET['id'];
$result = $wpdb->get_results("SELECT * FROM wp_customers WHERE id=$id");
foreach ($result as $key => $print) {
$name = $print->name;
$phone = $print->phone;
}
?>
<div class="container card content-center">
<centers>
<div class="card" style="padding:10px; background:white">
<form action="admin.php?page=update-customers" class="" method="post">
<h4>Update Records</h4>
<div class="mb-3 mt-3">
<label for="uname" class="form-label">Name:</label>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="text" class="form-control" id="unames" placeholder="Enter name" name="name"
value="<?php echo $name; ?>" required>
</div>
<div class="mb-3">
<label for="pwd" class="form-label">Mobile No:</label>
<input type="number" class="form-control" id="number" placeholder="Enter your number" name="mobile"
value="<?php echo $phone; ?>" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</centers>
</div>
update.php
<?php
global $wpdb;
$id = $_POST['id'];
$name = $_POST['name'];
$phone = $_POST['mobile'];
$q = $wpdb->query("UPDATE wp_customers SET name='$name',
phone='$phone' WHERE id='$id'");
if($q){ ?>
<script> window.location.href ="admin.php?page=edit-customers&&id=<?php echo $id; ?>";</script>
<?php }
else{
echo 'error';
}
?>