update_statement.php
<?php
//Config
$server = "localhost";
$user = "root";
$password = "";
$database = "address_book";
//Establishing a Connection to MySQL Server
$connection = mysqli_connect($server, $user, $password, $database);
//Check Connection
if (!$connection) {
die("<h2>Total Fail</h2> " . mysqli_connect_error());
} else {
echo "Connection Successfull <br>";
}
//SQL Command
$sql_command = "UPDATE people SET telephon=888999 WHERE name='John'";
if (mysqli_query($connection, $sql_command)) {
echo "SQL Command OK";
} else {
echo "SQL Error " . mysqli_error($connection) ;
}
?>
This SQL command updates the "telephon" field for the row(s) where the "name" field is equal to "John". Specifically, it sets the "telephon" field to 888999 for all rows where the "name" field is "John". If the query is successful, the message "SQL Command OK" is displayed. Otherwise, the error message returned by mysqli_error() is displayed.
When we run it:
Connection Successfull
SQL Command OK
No comments:
Post a Comment