Using the PHP Sql UPDATE command we can modify the data in the MySQL table.
syntax:
UPDATE table_name SET field_name = new_value WHERE [Clause]

Example:



<?php
$dbhost 
"localhost";
$dbuser "your_username";
$dbpass "your_password";
$dbname "basename";
$conn mysqli_connect($dbhost$dbuser$dbpass $dbname);
// Check connection
if (!$conn) {
die(
"Connection failed: " mysqli_connect_error());
}
$sql "UPDATE members SET firstname =`John` WHERE id=`1`";
if (
mysqli_query($conn$sql)) {
echo 
"The field has been updated sucessfuly.";
} else {
echo 
"The field has NOT been updated." mysqli_error($conn);
}
mysqli_close($conn);
 
?> 


Example how update multiple fields

syntax:
UPDATE table_name SET field_name1 = new_value, field_name2 = new_value, field_name3 = new_value, WHERE [Clause]



<?php
$dbhost 
"localhost";
$dbuser "your_username";
$dbpass "your_password";
$dbname "basename";
$conn mysqli_connect($dbhost$dbuser$dbpass $dbname);
// Check connection
if (!$conn) {
die(
"Connection failed: " mysqli_connect_error());
}
$sql "UPDATE members SET firstname =`John`, lastname=`Parker`, email=`johnparker@gmail` WHERE id=`1`";
if (
mysqli_query($conn$sql)) {
echo 
"The fields has been updated sucessfuly.";
} else {
echo 
"The fields has NOT been updated." mysqli_error($conn);
}
mysqli_close($conn);
 
?>









Privacy Policy