in reply to Help Copying records from one table to another.

Your immediate problem is the sequence
$sth->execute() $sth->finish() $sth->fetchrow_array()
followed by reusing $sth to hold a different statement, before you're done fetching results from the first.

This is masking a second problem, which is that if any of the data you're retrieving needs to be quoted, the SQL you're preparing inside of the loop is going to be bogus.

Use two statements, using bind variables for the INSERT. Prepare both outside of the loop.