in reply to Images, in links, in tables..... utter choas

Can you please define "all hell breaks loose"? Does your server give a dreaded 500 error? Something else? It's very hard for some of us to give sound advice without some additional info. Especially because we can't run your script without your DB or images.

For starters though, make your first three lines:

$|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser');
MrCromeDome