I have a form in php which works just fine, except that the user can see result without providing email and name fields. I want to add a php code that will echo to user that name and email is required before he gets to see the final answer. I have tried adding various if and else statements but the form stops working if i fiddle with the code. I would b really grateful for some help
<?php
$name = $_POST['fieldname5_1'];
$email = $_POST['fieldname6_1'];
$score = $_POST['fieldname158_1'];
if(empty($name) || empty($email))
{
echo "You did not fill out the required fields.";
}
else {
if($score<"6") {
echo " something1 $score";
} elseif($score<"11") {
echo " something2 $score";
} elseif($score<"30") {
echo " something3 $score";
} elseif($score<"81") {
echo " something4 $score";
} else {
echo " something5 $score";
}
}
$formcontent="something6 $score";
$recipient = "myemail@email.com, $email";
$subject = "Your test";
$mailheader = "From: myemail@email.com
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>