捕获“死”错误并将其粘贴到原始页面上

So, I have a form om my webpage which insert into a database. It throws a die(mysql_error()) into a blank page if not all fields have a value. I want this error message pasted over my form, but not loose the values already inputed. I have thought about both reloading the page with a page.php?error=... and making code to check if all fields have value (which will be long and feels unnecessary since what I want is already on my screen.

Do you think something like if(field1 has no value | field2 has no value | ....){ don't do anything and do rest is the best and most effectiv?

But if I want show which field is missing aswell, it will be a LOT of code...

in all of your input fields set the html value attribute to value = <?php echo @$_POST['fieldname'] ?>

also, instead of using die, use $error = mysql_error(); and then echo $error later on

You don't really want to output the exact die() error message, as the user won't be able to understand it, and chances if they would understand it, they're potentially the kind of users you don't want being able to see it!

Not really sure of your situation (as you didn't post any code) but from what you've said I'd suggest using try & catch, and handling any errors that occur, for example:

try {
    // perform your database query
} catch (SQLException $error_msg) { // catch the error if goes wrong
    //$error_msg contains the information from the error
    return 'We`re sorry, your form submission could not be handled at this time.';
}
// if we got to this stage, there were no problems
return 'success';

That way, you can verify the reasons why the Exception occured, catching the real error message so they don't see it, then returning some other output back to the user in a format that they can understand.