You're trying to run 3 queries instead of trying to run the query after the test...
$required = array('uexam_id', 'usubject', 'uexam_date');
$error = false;
//first check all required fields are not empty. if post has values
if(!empty($_POST))
{
foreach($required as $field)
if ( empty($_POST[$field]))
$error = true;
//a field was empty, show error
if ($error) {
die ("All fields are required! <a href='examisud.php'> Back to Form </a>");
}
//no error - try the query
else
{
$InsertQuery = "INSERT INTO Exam (exam_id, subject, exam_date) VALUES
($_POST[uexam_id],$_POST[usubject],$_POST[uexam_date])";
$result = mysql_query($InsertQuery, $con) or die('query Failure:'. mysql_error());
}
}
Also as a side note as im sure others will mention, mysql is deprecated, please look to using mysqli in the future. Also I notice the required fields don't have the 'u' before them as the query does. I assume this is a mistake?