No need, it's really very simple when you know how. Here's a couple of examples using your original source as a framework.
//extract($_REQUEST);
if ($_POST['submit'])
{
$user='someuser';
$host='localhost';
$password='somepassword';
$database="somedatabasename";
$connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
$db=mysql_select_db($database,$connection);
//Before you insert into the database just check all the fields have
//been filled in properly (if at all)
//First we initialize our error message variable ($err) to an empty array
//so that we can test to see if there are any errors later
$err=array();
//Now we can go through the variables one by one checking if they are OK
//This part can be compacted but I want to keep things simple
//Let's say the name must not be empty and can only contain letters and whitespace
if(!isset($_POST['name']) || $_POST['name']=='') {
$err[]='You must provide a name';
} elseif(!preg_match('/^[a-zA-Z\s]+$/',$_POST['name'])) {
//This is a regular expression saying it must contain only letters and whitespace (\s)
$err[]='The name field must consist of letters and whitespace only';
}
//Let's also say the email is compulsory and must be of the correct form
if(!isset($_POST['email']) || $_POST['email']=='') {
$err[]='You must provide and email';
} elseif(!preg_match('/^.*?@.*\..{2,3}$/',$_POST['email'])) {
//A very loose email regex, a little searching on this forum will
//bring up many many more specific ones.
$err[]='The email field does not appear to be in the correct format';
}
//Now, if you notice the first condition of each of those blocks is
//essentially the same
//if(!isset($_POST['field_name']) || $_POST['field_name']) {
// $err[]='You must provide a field_name';
//see?, This can therefore be grouped together into a loop.
$required_fields=array('name','email','contact_address','mobile','workhome_tel');
for($i=0;$i<count($required_fields);$i++) {
if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
$err[]='You must provide a '.$_POST[$required_fields[$i]];
}
}
//Once you have done the validation you will have a variable called $err which,
//if any errors occured will not be empty. So we test to see how many elements
//the $err array has in it to see if any errors occured
if(count($err)>0) {
//there were errors, re-display the form with bad values highlighted or something like that
} else {
//There were no errors so we can run the query
//....
HTH
Bubble