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”>
    <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>
    <font style=”font-size: 20px;”>Enter details for update</font>
    <form action=”form.php” method=”post”>
        <font style=”font-size: 20px;”>Enter email</font>
        <input type=”email” name=”email” required>
        <font style=”font-size: 20px;”>Name</font>
        <input type=”text” name=”name” required>
        <font style=”font-size: 20px;”>Phone</font>
        <input type=”text” name=”phone” required>
        <font style=”font-size: 20px;”>Location</font>
        <input type=”text” name=”loc” required>
        <input type=”submit” value=”submit”>

File – form.php

// 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!!”;
    $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.
} else {
    echo “query not executed!”;

File – phpmyadmin before

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

File – phpmyadmin after