in reply to HTML Form Submission & Save to MySQL

For short:
#!/usr/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header, $q->start_html; if ( $q->param("name") ) { # Validate data and insert it into DB Answer(); } else { Form(); } print $q->end_html; sub Form { print $q->start_form, "Your name: ", $q->textfield("name"), " ", $q->submit, $q->end_form; } sub Answer { print "Your name is ", $q->strong($q->param("name")) }
Use CGI

This way you validate data AFTER printing out the document header. If you want to validate data BEFORE you need to change the way you call those functions. You cannot print anything to the browser before printing the document header.

UPDATE: OOPSSS! I misunderstood your question! I'm sorry. I thought you were passing the form via CGI. But that's not the case.

If you're using somthing like: file.HTML(form)->file.cgi(save data, send a cookie)->file.HTML(answer with data) you might need javascript to read the cookie in the 3rd step.