ho fatto un debug del tuo script con XDebug ma vuoi saperne una bella? non c'è manco un errore con le correzioni che ti ho dato!!!