You can do it, but not the way you did. You just put everything in a form, and post the contents back to your script, only then can you save them to your MySQL table.
So basically your script should look like this :
<?php
if ($REQUEST_METHOD == "POST")
{
// check if data is valid, if not generate error message
if (valid_data())
{
// get all data & save to MySQL
mysql_connect(...);
mysql_query("insert ...");
etc.
// redirect to another page
Header("Location: thanks.html");
exit;
}
}
?>
<body>
<form name="<?=$PHP_SELF?>" method="POST">
... put your form data here ...
</form>
</body>