Update istat.php

Added error handling, changed SQL query vars