Fixed duplicate bug in SQL and updated php