For loop in mysql query

You would have to execute the query inside the loop; what your loop does is overwrite the $sql variable over and over, and when you get to the end, you execute it - the last instance of the loop.

Also, never do that.

(Seriously.)

Instead of looping the query, make the query insert multiple records at the same time.