The UPDATE statement is used to modify the existing data in a table.We can update single columns as well as multiple columns using UPDATE statement as per our requirement.SQL UPDATE Query is used to modify the existing records in a table.we can use the WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition
StudentID | StudentName | ParentsContact | Address | Country | DOB | Section |
Branch |
1 |
Liam | 10101010 | 23 MG road Banglore |
INDIA | 12/06 | A | CSE |
2 | Andrew | 20202020 | 2415 Anthony market str | Germany | 01/02 | A | ISE |
3 | Joshua | 30303030 | 26547 David church road | USA | 18/04 | B | CL |
4 | Ryan | 40404040 | 18 Krishna sq. Banglore |
INDIA | 26/12 | B | EE |
5 | Charles | 50505050 | 878 Eli Berguvsvägen 8 | INDIA | 23/11 | C | ECE |
$sql = "UPDATE Student SET StudentName='Jeo' WHERE Country='USA'";
<!DOCTYPE html>
<html lang="en">
<head>
<title>How to use SQL UPDATE Statement</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<br>
<br>
<br>
<div class="text-center">
<h1>SQL UPDATE Statement</h1>
</div>
<div class="well">
<?php
$connect = mysqli_connect("localhost", "root", "", "school_management");
if($connect === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "UPDATE Student SET StudentName='Juan' WHERE Country='USA'";
if(mysqli_query($connect, $sql)){
echo "<h1>Update Records successfully.</h1>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect);
}
mysqli_close($connect);
?>
</div>
<br>
</div>
</body>
</html>