Fixing PHP and SQL errors