How to display php last inserted id in alert box.

I am trying to get the last inserted id to be displayed in alert box. Can anyone help me out.
I can echo it out but I want to display the ID in alert box and redirect once the user clicks ok. Thank you so much. I am a new php coder.