I've created a toolset that allows me to add Form fields that we use in our
system. But now I want to take that a step further. I want to be able to write
corresponding PHP code above the HTML tag at a specific location. This while
looping through the formfields in the form and dynamically write the INSERT
and/or UPDATE query.
The last bit I can probably figure out. What I would like to know is how to
write the code above the HTML tag between <? ?> or with a search/replace of the
INSERT or UPDATE line in the code.

Can anyone give me some hints or tips on this?

Thanks in advance!