Update Record in the Database
×
Home Courses Community Support
Update Record in the Database

You have learned about Insert Query. Let's take another example to learn about update query.

We have a table which have below records:

ID Name Phone Email Message
1 Anuj 9898989898 email@emailserver.com It will be updated.
2 Ankur 5656565656 myemail@mydomain.com This row will be deleted.


Now run below query to update the first record, save in id 1-

<?php
$con = mysqli_connect("localhost","root","","myweb");
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
} 

$sql = "UPDATE form_data SET Message='This is updated Message.' WHERE id=2";
if ($con->query($sql) === TRUE) {
	echo "Message has been successfully updated.";
} else {
    echo "Error updating record: " . $con->error;
}
$con->close();
?>


This query will update the message "It will be updated." to "This is updated Message."

 

← Preview

Insert Data in Database

Next →

Delete Values From Database

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App