Change database technology to PDO

You really, really need to refactor this code. Right now, in your other PHP files there is a massive SQL injection vulnerability. Parameterized PDO will assist you to avoid this.