How can one check if a data record was successfully written to the database in PHP?
To check if a data record was successfully written to the database in PHP, you can use the mysqli_affected_rows() function after executing the query. This function returns the number of rows affected by the last INSERT, UPDATE, or DELETE query.
// Execute the query
$result = mysqli_query($conn, $query);
// Check if the query was successful
if ($result && mysqli_affected_rows($conn) > 0) {
echo "Record successfully written to the database.";
} else {
echo "Error writing record to the database.";
}