What are common pitfalls when using mysql_fetch_row() in PHP and how can they be avoided?

One common pitfall when using mysql_fetch_row() in PHP is not checking for false values returned when there are no more rows to fetch. This can lead to errors when trying to access non-existent rows. To avoid this, always check the return value of mysql_fetch_row() before using the fetched data.

$result = mysql_query("SELECT * FROM table");

if ($result) {
    while ($row = mysql_fetch_row($result)) {
        // process the fetched row
    }
} else {
    echo "Error fetching data from database";
}