How can PHP be used to update text in a MySQL database?

To update text in a MySQL database using PHP, you can use the SQL UPDATE statement with a WHERE clause to specify the record to be updated. You will need to establish a connection to the MySQL database, execute the SQL query using PHP, and handle any errors that may occur during the update process.

<?php
// Establish a connection to the MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Update text in the database
$new_text = "New text to be updated";
$id = 1; // ID of the record to be updated

$sql = "UPDATE table_name SET text_column = '$new_text' WHERE id = $id";

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

// Close the database connection
$conn->close();
?>