This is a hand coded php file with hand coded database references. I couldn't debug this without direct FTP access. I'd start by adding this to the top of the page:
<?php
ini_set("display_errors",1);
?>
That should make the page give a true error message instead of the general 500 error.