I did that once, too. The way DBs work is that you query, and they give a result resource thing. That result set isn't just a string, it's kind of like trying to echo an array, you get Array {. So, it should look like this:
<?php
$result = mysql_query("SELECT sum(hours) FROM project_hours WHERE project_id = 'p'");
$row = mysql_fetch_array($result);
$total_hours = $row['sum']; #The column gets named to sum when you use sum()
echo($total_hours);
?>