It looks like you are looping on the ProductMisc table, but inserting from the EB1 table. My guess is that the query isn't returning the results you expect. Try running that query in phpMyAdmin to make sure your joins are correct and that the value for ProductNames and ProductTypeName are what you expect.