What does it mean when mysql_affected_rows() returns -1 in PHP?

When mysql_affected_rows() returns -1 in PHP, it means that the query failed or there was an error in executing the query. This could be due to various reasons such as syntax errors, connection issues, or permissions problems. To solve this issue, you should first check for any error messages returned by the MySQL server and address them accordingly. Additionally, you can also verify the query syntax and ensure that the connection to the database is established properly.

$result = mysqli_query($connection, $query);

if($result === false){
    echo "Error: " . mysqli_error($connection);
} else {
    $affected_rows = mysqli_affected_rows($connection);
    echo "Affected rows: " . $affected_rows;
}