Hi folks

I have set up an form that when submitted sends an email, however I want to suppress the information in the email if it is left blank in the form.

an example of the existing PHP code I have is

?php


$to_email_address = "someone@someone.com";
$from_email_address = "$email";
$replay_email_address = "$email";
$returnpath_email_address = "someone@someone.com";

if (isset($_POST)){
   foreach($_POST as $k => $v){
      if(is_array($_POST[$k])){
         foreach ($_POST[$k] as $k1 => $v1){
            eval("\$$k" . "[". $k1 . "] = myAddSlashes(\$v1);");
         }
      } else {
         eval("\$$k = myAddSlashes(\$_POST['$k']);");
      }
   }
}

<tr>
   <td>Cylcing 1:</td>
   <td>$cycling1 </td>
</tr>
<tr>
   <td>Cycling Experience 1:</td>
   <td>$cyclingEx1 </td>
</tr>

inside the for each in array_post loop,
then only table rows for items in the post array will be generated.
no need for 'suppression'
I should have read this post before the other post

if (isset($_POST)){
   foreach($_POST as $k => $v){
      if(is_array($_POST[$k])){
         foreach ($_POST[$k] as $k1 => $v1){
            eval("\$$k" . "[". $k1 . "] = myAddSlashes(\$v1);");
         echo "<tr><td>".$k.":</td><td>".$v."</td></tr><tr><td>".$k1.":</td><td>".$v1."</td></tr>";  
 }
      } else {
         eval("\$$k = myAddSlashes(\$_POST['$k']);");
       echo "<tr><td>".$k.":</td><td>&nbsp;</td></tr>";  
  }
}
}
?>

(sort out the field names I didnt check)
(count the braces, I didnt check whether the echo statement is inside the right loop)
echo &or sprintf dependant on where you're putting the data.

A) Don't iterate through POST variables if you're doing any sort of key/value assignment. I (as a user) can put anything I want into POST and given that you're eval ing the code you immediately just opened yourself up to every attack under the sun

B) Why the heck are you using eval?

ok, this is all a bit beyond me

I had another reply from elsewhere that gave me

if ($cycling1 != ""){
$myBodyEmail .= "
<tr>
   <td>Cylcing 1:</td>
   <td>$cycling1 </td>
</tr>
<tr>
   <td>Cycling Experience 1:</td>
   <td>$cyclingEx1 </td>
</tr>";
}

however i am getting an error message when testing this that says

Parse error: syntax error, unexpected $end

full code is

<?php


$to_email_address = "someone@someone.com";
$from_email_address = "$email";
$replay_email_address = "$email";
$returnpath_email_address = "someone@someone.com";

if (isset($_POST)){
   foreach($_POST as $k => $v){
      if(is_array($_POST[$k])){
         foreach ($_POST[$k] as $k1 => $v1){
            eval("\$$k" . "[". $k1 . "] = myAddSlashes(\$v1);");
         }
      } else {
         eval("\$$k = myAddSlashes(\$_POST['$k']);");
      }
   }
}
if ($cot_bedding == "on"){
 $cot_bedding = "Yes";
}else{
 $cot_bedding = "No";
}
if ($steriliser == "on"){
 $steriliser = "Yes";
}else{
 $steriliser = "No";
}
if ($high_chair == "on"){
 $high_chair = "Yes";
}else{
 $high_chair = "No";
}
if ($bouncy_chair == "on"){
 $bouncy_chair = "Yes";
}else{
 $bouncy_chair = "No";
}
if ($food_mixer == "on"){
 $food_mixer = "Yes";
}else{
 $food_mixer = "No";
}
$subject = "Pre-arrival form";
// pre-arrival form
$myBodyEmail = "
<html>

<body>
<table width='600' cellpadding='2' cellspacing='0'>
<tr>
   <td width='150'>Name:</td>
   <td>$name </td>
</tr>
<tr>
   <td>Email:</td>
   <td>$email </td>
</tr>
<tr>
   <td>Mobile 1:</td>
   <td>$tel1 </td>
</tr>
<tr>
   <td>Mobile 2:</td>
   <td>$tel2 </td>
</tr>
<tr>
   <td>Flight Arrival Details:</td>
   <td>$flight_details_arrival </td>
</tr>
<tr>
   <td>Arrival Time:</td>
   <td>$arrival_time </td>
</tr>
<tr>
   <td>Directions:</td>
   <td>$directions </td>
</tr>
<tr>
   <td>First Child:</td>
   <td>$child1 </td>
</tr>
<tr>
   <td>Second Child:</td>
   <td>$child2 </td>
</tr>
<tr>
   <td>Third Child:</td>
   <td>$child3 </td>
</tr>
<tr>
   <td>Fourth Child:</td>
   <td>$child4 </td>
</tr>
<tr>
   <td>Cot Bedding:</td>
   <td>$cot_bedding </td>
</tr>
<tr>
   <td>Steriliser:</td>
   <td>$steriliser </td>
</tr>
<tr>
   <td>High Chair:</td>
   <td>$high_chair </td>
</tr>
<tr>
   <td>Bouncy Chair:</td>
   <td>$bouncy_chair </td>
</tr>
<tr>
   <td>Food Mixer:</td>
   <td>$food_mixer </td>
</tr>
<tr>
   <td>Catering:</td>
   <td>$catering </td>
</tr>
<tr>
   <td>Catered Meals:</td>
   <td>$catered_meals </td>
</tr>
<tr>
   <td>Special Request:</td>
   <td>$special_request </td>
</tr>";

if ($cycling1 != ""){
$myBodyEmail .= "
<tr>
   <td>Cylcing 1:</td>
   <td>$cycling1 </td>
</tr>
<tr>
   <td>Cycling Experience 1:</td>
   <td>$cyclingEx1 </td>
</tr>";
}

if ($cycling2 != ""){
$myBodyEmail .= "
<tr>
   <td>Cylcing 2:</td>
   <td>$cycling2 </td>
</tr>
<tr>
   <td>Cycling Experience 2:</td>
   <td>$cyclingEx2 </td>
</tr>";

$myBodyEmail .= "
<tr>
   <td>Cylcing 3:</td>
   <td>$cycling3 </td>
</tr>
<tr>
   <td>Cycling Experience 3:</td>
   <td>$cyclingEx3 </td>
</tr>

<tr>
   <td>Cylcing 4:</td>
   <td>$cycling4 </td>
</tr>
<tr>
   <td>Cycling Experience 4:</td>
   <td>$cyclingEx4 </td>
</tr>
<tr>
   <td>Archery 1:</td>
   <td>$archery1 </td>
</tr>
<tr>
   <td>Archery Experience 1:</td>
   <td>$archeryEx1 </td>
</tr>
<tr>
   <td>Archery 2:</td>
   <td>$archery2 </td>
</tr>
<tr>
   <td>Archery Experience 2:</td>
   <td>$archeryEx2 </td>
</tr>
<tr>
   <td>Archery 3:</td>
   <td>$archery3 </td>
</tr>
<tr>
   <td>Archery Experience 3:</td>
   <td>$archeryEx3 </td>
</tr>

<tr>
   <td>Archery 4:</td>
   <td>$archery4 </td>
</tr>
<tr>
   <td>Archery Experience 4:</td>
   <td>$archeryEx4 </td>
</tr>
<tr>
   <td>Sailing 1:</td>
   <td>$sailing1 </td>
</tr>
<tr>
   <td>Sailing Exp 1:</td>
   <td>$sailingEx1 </td>
</tr>
<tr>
   <td>Sailing 2:</td>
   <td>$sailing2 </td>
</tr>
<tr>
   <td>Sailing Exp 2:</td>
   <td>$sailingEx2 </td>
</tr>
<tr>
   <td>Sailing 3:</td>
   <td>$sailing3 </td>
</tr>
<tr>
   <td>Sailing Exp 3:</td>
   <td>$sailingEx3 </td>
</tr>

<tr>
   <td>Sailing 4:</td>
   <td>$sailing4 </td>
</tr>
<tr>
   <td>Sailing Exp 4:</td>
   <td>$sailingEx4 </td>
</tr>
<tr>
   <td>Pedalo 1:</td>
   <td>$pedalo1 </td>
</tr>
<tr>
   <td>Pedalo Experience 1:</td>
   <td>$pedaloEx1 </td>
</tr>
<tr>
   <td>Pedalo 2:</td>
   <td>$pedalo2 </td>
</tr>
<tr>
   <td>Pedalo Experience 2:</td>
   <td>$pedaloEx2 </td>
</tr>
<tr>
   <td>Pedalo 3:</td>
   <td>$pedalo3 </td>
</tr>
<tr>
   <td>Pedalo Experience 3:</td>
   <td>$pedaloEx3 </td>
</tr>

<tr>
   <td>Pedalo 4:</td>
   <td>$pedalo4 </td>
</tr>
<tr>
   <td>Pedalo Experience 4:</td>
   <td>$pedaloEx4 </td>
</tr>
<tr>
   <td>Hiking 1:</td>
   <td>$hiking1 </td>
</tr>
<tr>
   <td>Hiking Experience 1:</td>
   <td>$hikingEx1 </td>
</tr>
<tr>
   <td>Hiking 2:</td>
   <td>$hiking2 </td>
</tr>
<tr>
   <td>Hiking Experience 2:</td>
   <td>$hikingEx2 </td>
</tr>
<tr>
   <td>Hiking 3:</td>
   <td>$hiking3 </td>
</tr>
<tr>
   <td>Hiking Experience 3:</td>
   <td>$hikingEx3 </td>
</tr>

<tr>
   <td>Hiking 4:</td>
   <td>$hiking4 </td>
</tr>
<tr>
   <td>Hiking Experience 4:</td>
   <td>$hikingEx4 </td>
</tr>
<tr>
   <td>Tennis 1:</td>
   <td>$tennis1 </td>
</tr>
<tr>
   <td>Tennis Experience 1:</td>
   <td>$tennisEx1 </td>
</tr>
<tr>
   <td>Tennis 2:</td>
   <td>$tennis2 </td>
</tr>
<tr>
   <td>Tennis Experience 2:</td>
   <td>$tennisEx2 </td>
</tr>
<tr>
   <td>Tennis 3:</td>
   <td>$tennis3 </td>
</tr>
<tr>
   <td>Tennis Experience 3:</td>
   <td>$tennisEx3 </td>
</tr>

<tr>
   <td>Tennis 4:</td>
   <td>$tennis4 </td>
</tr>
<tr>
   <td>Tennis Experience 4:</td>
   <td>$tennisEx4 </td>
</tr>
<tr>
   <td>Golf 1:</td>
   <td>$golf1 </td>
</tr>
<tr>
   <td>Golf Experience 1:</td>
   <td>$golfEx1 </td>
</tr>
<tr>
   <td>Golf 2:</td>
   <td>$golf2 </td>
</tr>
<tr>
   <td>Golf Experience 2:</td>
   <td>$golfEx2 </td>
</tr>
<tr>
   <td>Golf 3:</td>
   <td>$golf3 </td>
</tr>
<tr>
   <td>Golf Experience 3:</td>
   <td>$golfEx3 </td>
</tr>

<tr>
   <td>Golf 4:</td>
   <td>$golf4 </td>
</tr>
<tr>
   <td>Golf Experience 4:</td>
   <td>$golfEx4 </td>
</tr>
<tr>
   <td>French 1:</td>
   <td>$french1 </td>
</tr>
<tr>
   <td>French Experience 1:</td>
   <td>$frenchEx1 </td>
</tr>
<tr>
   <td>French 2:</td>
   <td>$french2 </td>
</tr>
<tr>
   <td>French Experience 2:</td>
   <td>$frenchEx2 </td>
</tr>
<tr>
   <td>French 3:</td>
   <td>$french3 </td>
</tr>
<tr>
   <td>French Experience 3:</td>
   <td>$frenchEx3 </td>
</tr>

<tr>
   <td>French 4:</td>
   <td>$french4 </td>
</tr>
<tr>
   <td>French Experience 4:</td>
   <td>$frenchEx4 </td>
</tr>
<tr>
   <td>Horse 1:</td>
   <td>$horse1 </td>
</tr>
<tr>
   <td>Horse Experience 1:</td>
   <td>$horseEx1 </td>
</tr>
<tr>
   <td>Horse 2:</td>
   <td>$horse2 </td>
</tr>
<tr>
   <td>Horse Experience 2:</td>
   <td>$horseEx2 </td>
</tr>
<tr>
   <td>Horse 3:</td>
   <td>$horse3 </td>
</tr>
<tr>
   <td>Horse Experience 3:</td>
   <td>$horseEx3 </td>
</tr>

<tr>
   <td>Horse 4:</td>
   <td>$horse4 </td>
</tr>
<tr>
   <td>Horse Experience 4:</td>
   <td>$horseEx4 </td>
</tr>
<tr>
   <td>Pony 1:</td>
   <td>$pony1 </td>
</tr>
<tr>
   <td>Pony Experience 1:</td>
   <td>$ponyEx1 </td>
</tr>
<tr>
   <td>Pony 2:</td>
   <td>$pony2 </td>
</tr>
<tr>
   <td>Pony Experience 2:</td>
   <td>$ponyEx2 </td>
</tr>
<tr>
   <td>Pony 3:</td>
   <td>$pony3 </td>
</tr>
<tr>
   <td>Pony Experience 3:</td>
   <td>$ponyEx3 </td>
</tr>

<tr>
   <td>Pony 4:</td>
   <td>$pony4 </td>
</tr>
<tr>
   <td>Pony Experience 4:</td>
   <td>$ponyEx4 </td>
</tr>
<tr>
   <td>Carriage Rides 1:</td>
   <td>$carriage1 </td>
</tr>
<tr>
   <td>Carriage Rides 2:</td>
   <td>$carriage2 </td>
</tr>
<tr>
   <td>Carriage Rides 3:</td>
   <td>$carriage3 </td>
</tr>
<tr>
   <td>Carriage Rides 4:</td>
   <td>$carriage4 </td>
</tr>
<tr>
   <td>Fishing 1:</td>
   <td>$fishing1 </td>
</tr>
<tr>
   <td>Fishing Experience 1:</td>
   <td>$fishingEx1 </td>
</tr>
<tr>
   <td>Fishing 2:</td>
   <td>$fishing2 </td>
</tr>
<tr>
   <td>Fishing Experience 2:</td>
   <td>$fishingEx2 </td>
</tr>
<tr>
   <td>Fishing 3:</td>
   <td>$fishing3 </td>
</tr>
<tr>
   <td>Fishing Experience 3:</td>
   <td>$fishingEx3 </td>
</tr>

<tr>
   <td>Fishing 4:</td>
   <td>$fishing4 </td>
</tr>
<tr>
   <td>Fishing Experience 4:</td>
   <td>$fishingEx4 </td>
</tr>
<tr>
   <td>Windsurfing 1:</td>
   <td>$windsurfing1 </td>
</tr>
<tr>
   <td>Windsurfing Experience 1:</td>
   <td>$windsurfingEx1 </td>
</tr>
<tr>
   <td>Windsurfing 2:</td>
   <td>$windsurfing2 </td>
</tr>
<tr>
   <td>Windsurfing Experience 2:</td>
   <td>$windsurfingEx2 </td>
</tr>
<tr>
   <td>Windsurfing 3:</td>
   <td>$windsurfing3 </td>
</tr>
<tr>
   <td>Windsurfing Experience 3:</td>
   <td>$windsurfingEx3 </td>
</tr>

<tr>
   <td>Windsurfing 4:</td>
   <td>$windsurfing4 </td>
</tr>
<tr>
   <td>Windsurfing Experience 4:</td>
   <td>$windsurfingEx4 </td>
</tr>
<tr>
   <td>Canoeing 1:</td>
   <td>$canoeing1 </td>
</tr>
<tr>
   <td>Canoeing Experience 1:</td>
   <td>$canoeingEx1 </td>
</tr>
<tr>
   <td>Canoeing 2:</td>
   <td>$canoeing2 </td>
</tr>
<tr>
   <td>Canoeing Experience 2:</td>
   <td>$canoeingEx2 </td>
</tr>
<tr>
   <td>Canoeing 3:</td>
   <td>$canoeing3 </td>
</tr>
<tr>
   <td>Canoeing Experience 3:</td>
   <td>$canoeingEx3 </td>
</tr>

<tr>
   <td>Canoeing 4:</td>
   <td>$canoeing4 </td>
</tr>
<tr>
   <td>Canoeing Experience 4:</td>
   <td>$canoeingEx4 </td>
</tr>
<tr>
   <td>Tree Top 1:</td>
   <td>$treetop1 </td>
</tr>
<tr>
   <td>Tree Top Experience 1:</td>
   <td>$treetopEx1 </td>
</tr>
<tr>
   <td>Tree Top 2:</td>
   <td>$treetop2 </td>
</tr>
<tr>
   <td>Tree Top Experience 2:</td>
   <td>$treetopEx2 </td>
</tr>
<tr>
   <td>Tree Top 3:</td>
   <td>$treetop3 </td>
</tr>
<tr>
   <td>Tree Top Experience 3:</td>
   <td>$treetopEx3 </td>
</tr>

<tr>
   <td>Tree Top 4:</td>
   <td>$treetop4 </td>
</tr>
<tr>
   <td>Tree Top Experience 4:</td>
   <td>$treetopEx4 </td>
</tr>
<tr>
   <td>Rock Climbing 1:</td>
   <td>$rock1 </td>
</tr>
<tr>
   <td>Rock Climbing Experience 1:</td>
   <td>$rockEx1 </td>
</tr>
<tr>
   <td>Rock Climbing 2:</td>
   <td>$rock2 </td>
</tr>
<tr>
   <td>Rock Climbing Experience 2:</td>
   <td>$rockEx2 </td>
</tr>
<tr>
   <td>Rock Climbing 3:</td>
   <td>$rock3 </td>
</tr>
<tr>
   <td>Rock Climbing Experience 3:</td>
   <td>$rockEx3 </td>
</tr>

<tr>
   <td>Rock Climbing 4:</td>
   <td>$rock4 </td>
</tr>
<tr>
   <td>Rock Climbing Experience 4:</td>
   <td>$rockEx4 </td>
</tr>

</table>
</body>
</html>";

mail($to_email_address, $subject, $myBodyEmail, "From: $from_email_address\r\nReply-To: $replay_email_address\r\nReturn-Path: $returnpath_email_address\r\nMIME-Version:1.0\r\nContent-Type: text/html");
header("");
exit;


function myAddSlashes($string) {
   if (get_magic_quotes_gpc()==1) {
      return ($string);
   } else {
      return (addslashes($string));
   }
}
   
?>

i think i have solved the Parse Error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.