Fixed bugs due to mysql.php being included more than once. I should have been using include_once function in the php. This was a bigger problem than I thought. I have now replaced all occurances of not using include_once.