To ensure that the while only executes when the query succeeded you could write:
if ($query)
while($res = mysql_fetch_assoc($query)) {
mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub = ".$hoje) or die(mysql_error());
}
Notice the absence of the $query= assignment within the loop. For an UPDATE you don't want to read any results. And you are checking the outcoume with the or die already anyway.