dove é settata $id ?

se testi il codice che ho postato vedrai che funziona.