Here we will, create a update prepared query for updating record into table..

  • Update person name, phone, and location on the basics of their email address using prepared statement.

File – form.html

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>update form</title>
</head>
<body>
    <br>
    <font style=”font-size: 20px;”>Enter details for update</font>
    <br>
    <br>
  
    <form action=”form.php” method=”post”>
        <font style=”font-size: 20px;”>Enter email</font>
        <br>
        <input type=”email” name=”email” required>
        <br><br>
        <font style=”font-size: 20px;”>Name</font>
        <br>
        <input type=”text” name=”name” required>
        <br><br>
        <font style=”font-size: 20px;”>Phone</font>
        <br>
        <input type=”text” name=”phone” required>
        <br><br>
        <font style=”font-size: 20px;”>Location</font>
        <br>
        <input type=”text” name=”loc” required>
        <br><br>
        <input type=”submit” value=”submit”>
    </form>
 
</body>
</html>
output

File – form.php

<?php
error_reporting(0);
// creating connection with mysql-database.
$conn = mysqli_connect(‘localhost’,’root’,”,’prepared’);
 
// ? = annonimos placeholder.
$sql=”UPDATE customers SET name=?,location=?,phone=? WHERE email=?”;
$query = mysqli_prepare($conn,$sql);
 
// if query failed then it will stoped here!
if ($query) {
    echo “<br><br> your query executed! record update!!”;
    mysqli_stmt_bind_param($query,’ssis’,$name,$loc,$phone,$email);
   
    $name = $_POST[‘name’];
    $phone = $_POST[‘phone’];
    $loc = $_POST[‘loc’];
    $email = $_POST[’email’];
 
    $name = mysqli_real_escape_string($conn,$name);
    $phone = mysqli_real_escape_string($conn,$phone);
    $loc = mysqli_real_escape_string($conn,$loc);
    $email = mysqli_real_escape_string($conn,$email);
 
    // executing prepared statement.
    mysqli_stmt_execute($query);
 
} else {
    echo “query not executed!”;
}
?>
output

File – phpmyadmin before

Note: we have update person’s name and location on the basics of their email address.

File – phpmyadmin after