L'errore è qui:

if ($records=mysql_fetch_assoc($res))

Correggi in:

if ($records=mysql_fetch_assoc($sql))