Jump to content

Sending form in an email


dreampho

Recommended Posts

Hi. I have a form which I have been helped with along the way through this forum. I am so close to the finishing line, but am stuck on one thing.

 

In the form a list of diseases are taken from the database, and shown as checkboxes. When the form is submitted I want the details to be sent in an email. I have worked out how to include all of the fields accept the diseases.

 

Could somebody please take a look at my code and tell me how I can include the checked disease values in the email part of the code at the top.

 

I have included the parts of the form and code that should be needed, as it was too large for the thread.

 

Thank you to anyone that can help.

 

<?php

/* Moderators Confirmation */

$EmailTo = "my email";
$Headers .= "From: email@email.com\r\nReply-To: ". ($_POST['email']) . "\r\n";
$Subject = "Enquiry Form";
$Headers .= "MIME-Version: 1.0\r\n";
$Headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td></td></tr>";
$message .= "<tr><td></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Title:</strong> </td><td style='color: #990000;'>" . ($_POST['title']) . "</td></tr>";
$message .= "<tr><td width='400'><strong>Full Name:</strong> </td><td style='color: #990000;'>" . ($_POST['forename']) . " " . ($_POST['surname']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></div></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Address:</strong> </td><td style='color: #990000;'>" . ($_POST['address_1']) . "</td></tr>";
$message .= "<tr><td><strong></strong> </td><td style='color: #990000;'>" . ($_POST['address_2']) . "</td></tr>";
$message .= "<tr><td><strong>City:</strong> </td><td style='color: #990000;'>" . ($_POST['address_city']) . "</td></tr>";
$message .= "<tr><td><strong>County:</strong> </td><td style='color: #990000;'>" . ($_POST['address_county']) . "</td></tr>";
$message .= "<tr><td><strong>Country:</strong> </td><td style='color: #990000;'>" . ($_POST['address_country']) . "</td></tr>";
$message .= "<tr><td><strong>Postcode:</strong> </td><td style='color: #990000;'>" . ($_POST['address_postcode']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Email:</strong> </td><td style='color: #990000;'>" . ($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Primary Phone:</strong> </td><td style='color: #990000;'>" . ($_POST['phone_1']) . "</td></tr>";
$message .= "<tr><td><strong>Secondary Phone:</strong> </td><td style='color: #990000;'>" . ($_POST['phone_2']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Age Group:</strong> </td><td style='color: #990000;'>" . ($_POST['currently']) . "</td></tr>";
$message .= "<tr><td><strong>Experience:</strong> </td><td style='color: #990000;'>" . ($_POST['occupation']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Date of Birth:</strong> </td><td style='color: #990000;'>" . ($_POST['dd']) . " / " . ($_POST['mm']) . " / " . ($_POST['yyyy']) . "</td></tr>";
$message .= "<tr><td><strong>Marital Status:</strong> </td><td style='color: #990000;'>" . ($_POST['marital']) . "</td></tr>";
$message .= "<tr><td><strong>Height:</strong> </td><td style='color: #990000;'>" . ($_POST['height_ft']) . " ft " . ($_POST['height_inches']) . " inches</td></tr>";
$message .= "<tr><td><strong>Weight:</strong> </td><td style='color: #990000;'>" . ($_POST['weight_stone']) . " stone " . ($_POST['weight_kg']) . " kg</td></tr>";
$message .= "<tr><td><strong>Number of Children:</strong> </td><td style='color: #990000;'>" . ($_POST['children']) . "</td></tr>";
$message .= "<tr><td><strong>Doctors Name:</strong> </td><td style='color: #990000;'>" . ($_POST['doctor']) . "</td></tr>";
$message .= "<tr><td><strong>Allow Contact with Doctor:</strong> </td><td style='color: #990000;'>" . ($_POST['contact_doctor']) . "</td></tr>";
$message .= "<tr><td><strong>Health Concerns:</strong> </td><td style='color: #990000;'>" . ($_POST['health_concerns']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you had any surgery, operations, major dental work or broken bones?</strong> </td><td style='color: #990000;'>" . ($_POST['q1_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q1_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you had any medical investigative procedures, such as X-rays, mammograms, blood tests, etc?</strong> </td><td style='color: #990000;'>" . ($_POST['q2_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q2_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you suffered a recent emotional trauma or one in the past, which still affects you?</strong> </td><td style='color: #990000;'>" . ($_POST['q3_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q3_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Are you currently taking any medication or supplements?</strong> </td><td style='color: #990000;'>" . ($_POST['q4_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q4_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Do you have a history of reoccurring Thrush or Cystitis?</strong> </td><td style='color: #990000;'>" . ($_POST['q5_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q5_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>How did you hear about us?</strong> </td><td style='color: #990000;'>" . ($_POST['hear']) . "</td></tr>";
$message .= "</table>";
$message .= "</table>";
$message .= "</body></html>";

/* Users Confirmation */

$EmailTo2 .= "" . ($_POST['email']) . "";
$Headers2 .= "From: Me";
$Subject2 = "Confirmation";
$Headers2 .= "MIME-Version: 1.0\r\n";
$Headers2 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message2 = '<html><body>';
$message2 .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message2 .= "<tr><td></td></tr>";
$message2 .= "<tr><td></td></tr>";
$message2 .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message2 .= "<tr><td>Thank you. Your consultation form has been received. </tr>";
$message2 .= "</table>";
$message2 .= "</table>";
$message2 .= "</body></html>";




$dbHostname = 'localhost';
$dbUsername = 'username';
$dbPassword = 'password';
$dbDatabase = 'database';

$dbCon = mysql_connect($dbHostname, $dbUsername, $dbPassword) or die('Error: Unable able to connect: ' . mysql_error());
$dbSel = mysql_select_db($dbDatabase, $dbCon) or die('Error: Unable to select database: ' . mysql_error());

$Answer=$_POST['Answer'];
$Yanswer=$_POST['Yanswer'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

	if ($Answer==$Yanswer) {
		mail($EmailTo, $Subject, $message, $Headers);
		mail($EmailTo2, $Subject2, $message2, $Headers2);

		mysql_query("INSERT INTO user SET 
		title = '" . $_POST['title'] . "', 
		forename = '" . $_POST['forename'] . "', 
		surname = '" . $_POST['surname'] . "', 
		address_1 = '" . $_POST['address_1'] . "', 
		address_2 = '" . $_POST['address_2'] . "', 
		address_city = '" . $_POST['address_city'] . "', 
		address_county = '" . $_POST['address_county'] . "', 
		address_country = '" . $_POST['address_country'] . "', 
		address_postcode = '" . $_POST['address_postcode'] . "', 
		email = '" . $_POST['email'] . "', 
		phone_1 = '" . $_POST['phone_1'] . "', 
		phone_2 = '" . $_POST['phone_2'] . "', 
		currently = '" . $_POST['currently'] . "', 
		occupation = '" . $_POST['occupation'] . "', 
		dd = '" . $_POST['dd'] . "', 
		mm = '" . $_POST['mm'] . "', 
		yyyy = '" . $_POST['yyyy'] . "', 
		marital = '" . $_POST['marital'] . "', 
		height_ft = '" . $_POST['height_ft'] . "', 
		height_inches = '" . $_POST['height_inches'] . "', 
		weight_stone = '" . $_POST['weight_stone'] . "', 
		weight_kg = '" . $_POST['weight_kg'] . "', 
		children = '" . $_POST['children'] . "', 
		doctor = '" . $_POST['doctor'] . "', 
		contact_doctor = '" . $_POST['contact_doctor'] . "', 
		health_concerns = '" . $_POST['health_concerns'] . "', 
		q1_yes_no = '" . $_POST['q1_yes_no'] . "', 
		q1_yes = '" . $_POST['q1_yes'] . "', 
		q2_yes_no = '" . $_POST['q2_yes_no'] . "', 
		q2_yes = '" . $_POST['q2_yes'] . "', 
		q3_yes_no = '" . $_POST['q3_yes_no'] . "', 
		q3_yes = '" . $_POST['q3_yes'] . "', 
		q4_yes_no = '" . $_POST['q4_yes_no'] . "', 
		q4_yes = '" . $_POST['q4_yes'] . "', 
		q5_yes_no = '" . $_POST['q5_yes_no'] . "', 
		q5_yes = '" . $_POST['q5_yes'] . "', 
		hear = '" . $_POST['hear'] . "'") or die('Error: Unable to execute query: ' . mysql_error());


		$user_id = mysql_insert_id();

		// Insert Diseases
		foreach ($_POST['disease'] AS $key => $value) {
			mysql_query("INSERT INTO user_to_disease SET user_id = '" . (int)$user_id . "', disease_id = '" . (int)$key . "'");
		}

		print "<meta http-equiv=\"refresh\" content=\"0;URL=consult-success\">";
    	} else {
		print "<meta http-equiv=\"refresh\" content=\"0;URL=consult-tryagain\">";

	}
}

// Check URL parameters for user_id
if (empty($_GET['user_id'])) {
	$error['missing_user_id'] = 'Error: Missing user_id in query parameters.';
} elseif ($_GET['user_id']) {
	$query = mysql_query("SELECT DISTINCT * FROM user WHERE user_id = '" . (int)$_GET['user_id'] . "'");
	$result = mysql_fetch_assoc($query);
}

?>

 

    <div class="scrollbox" style="width:100%;">
					<?php

						// Select All Records from Database
						$query = mysql_query("SELECT * FROM disease ORDER BY name ASC") or die('Error: Unable to execute query: ' . mysql_error());

						if ($query) {
							if (is_resource($query)) {
								$i = 0;
								$data = array();

								while ($result = mysql_fetch_assoc($query)) {
									$data[$i] = $result;
									$i++;
								}

								mysql_free_result($query);

								$results = array();
								$results = $data;

								unset($data);
							}
						} else {
							echo '<div class="warning">No results returned</div>';
						}

						$rowOne = 'rowOne';
						$rowTwo = 'rowTwo';
						$rowCount = 0;

					?>
					<?php foreach ($results as $disease) { ?>
						<?php $rowClass = ($rowCount % 2) ? $rowTwo : $rowOne; ?>
							<div class="<?php echo $rowClass; ?>"><input name="disease[<?php echo $disease['disease_id']; ?>]" type="checkbox" /><?php echo $disease['name']; ?></div>
						<?php $rowCount++; ?>
					<?php } ?>
					</div>

Link to comment
Share on other sites

same way as you are inserting them into the database

 

$disease=$_POST['disease'];
$message.="<tr><td>";
foreach ($disease as $issue) {
     $message.="Checked disease is $issue<br/>";
}
$message.="</td></tr>";

 

put that in the message section where you want it to appear

Link to comment
Share on other sites

It still shows the error. Here is what I have. I may have done something silly, could you possibly check my code?

 

<div class="scrollbox" style="width:100%;">
					<?php

						// Select All Records from Database
						$query = mysql_query("SELECT * FROM disease ORDER BY name ASC") or die('Error: Unable to execute query: ' . mysql_error());

						if ($query) {
							if (is_resource($query)) {
								$i = 0;
								$data = array();

								while ($result = mysql_fetch_assoc($query)) {
									$data[$i] = $result;
									$i++;
								}

								mysql_free_result($query);

								$results = array();
								$results = $data;

								unset($data);
							}
						} else {
							echo '<div class="warning">No results returned</div>';
						}

						$rowOne = 'rowOne';
						$rowTwo = 'rowTwo';
						$rowCount = 0;

					?>
					<?php foreach ($results as $disease) { ?>
						<?php $rowClass = ($rowCount % 2) ? $rowTwo : $rowOne; ?>
							<div class="<?php echo $rowClass; ?>"><input name="disease[<?php echo $disease['disease_id']; ?>]" type="checkbox" value="<?php echo $disease['name']; ?>" /><?php echo $disease['name']; ?></div>
						<?php $rowCount++; ?>
					<?php } ?>
					</div>

 

	$EmailTo = "email";
$Headers .= "From: email@email.com\r\nReply-To: ". ($_POST['email']) . "\r\n";
$Subject = "Enquiry Form";
$Headers .= "MIME-Version: 1.0\r\n";
$Headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td></td></tr>";
$message .= "<tr><td></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Title:</strong> </td><td style='color: #990000;'>" . ($_POST['title']) . "</td></tr>";
$message .= "<tr><td width='400'><strong>Full Name:</strong> </td><td style='color: #990000;'>" . ($_POST['forename']) . " " . ($_POST['surname']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></div></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Address:</strong> </td><td style='color: #990000;'>" . ($_POST['address_1']) . "</td></tr>";
$message .= "<tr><td><strong></strong> </td><td style='color: #990000;'>" . ($_POST['address_2']) . "</td></tr>";
$message .= "<tr><td><strong>City:</strong> </td><td style='color: #990000;'>" . ($_POST['address_city']) . "</td></tr>";
$message .= "<tr><td><strong>County:</strong> </td><td style='color: #990000;'>" . ($_POST['address_county']) . "</td></tr>";
$message .= "<tr><td><strong>Country:</strong> </td><td style='color: #990000;'>" . ($_POST['address_country']) . "</td></tr>";
$message .= "<tr><td><strong>Postcode:</strong> </td><td style='color: #990000;'>" . ($_POST['address_postcode']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Email:</strong> </td><td style='color: #990000;'>" . ($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Primary Phone:</strong> </td><td style='color: #990000;'>" . ($_POST['phone_1']) . "</td></tr>";
$message .= "<tr><td><strong>Secondary Phone:</strong> </td><td style='color: #990000;'>" . ($_POST['phone_2']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Age Group:</strong> </td><td style='color: #990000;'>" . ($_POST['currently']) . "</td></tr>";
$message .= "<tr><td><strong>Experience:</strong> </td><td style='color: #990000;'>" . ($_POST['occupation']) . "</td></tr>";
$message .= "</table>";
$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Date of Birth:</strong> </td><td style='color: #990000;'>" . ($_POST['dd']) . " / " . ($_POST['mm']) . " / " . ($_POST['yyyy']) . "</td></tr>";
$message .= "<tr><td><strong>Marital Status:</strong> </td><td style='color: #990000;'>" . ($_POST['marital']) . "</td></tr>";
$message .= "<tr><td><strong>Height:</strong> </td><td style='color: #990000;'>" . ($_POST['height_ft']) . " ft " . ($_POST['height_inches']) . " inches</td></tr>";
$message .= "<tr><td><strong>Weight:</strong> </td><td style='color: #990000;'>" . ($_POST['weight_stone']) . " stone " . ($_POST['weight_kg']) . " kg</td></tr>";
$message .= "<tr><td><strong>Number of Children:</strong> </td><td style='color: #990000;'>" . ($_POST['children']) . "</td></tr>";
$message .= "<tr><td><strong>Doctors Name:</strong> </td><td style='color: #990000;'>" . ($_POST['doctor']) . "</td></tr>";
$message .= "<tr><td><strong>Allow Contact with Doctor:</strong> </td><td style='color: #990000;'>" . ($_POST['contact_doctor']) . "</td></tr>";
$message .= "<tr><td><strong>Health Concerns:</strong> </td><td style='color: #990000;'>" . ($_POST['health_concerns']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$disease =$_POST['disease'];
$message .="<tr><td>"; 
foreach ($disease as $issue) {
$message .="Checked disease is $issue<br/>";
}
$message .="</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you had any surgery, operations, major dental work or broken bones?</strong> </td><td style='color: #990000;'>" . ($_POST['q1_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q1_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you had any medical investigative procedures, such as X-rays, mammograms, blood tests, etc?</strong> </td><td style='color: #990000;'>" . ($_POST['q2_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q2_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Have you suffered a recent emotional trauma or one in the past, which still affects you?</strong> </td><td style='color: #990000;'>" . ($_POST['q3_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q3_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Are you currently taking any medication or supplements?</strong> </td><td style='color: #990000;'>" . ($_POST['q4_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q4_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>Do you have a history of reoccurring Thrush or Cystitis?</strong> </td><td style='color: #990000;'>" . ($_POST['q5_yes_no']) . "</td></tr>";
$message .= "<tr><td style='color: #990000;'><strong>If yes:</strong> </td><td style='color: #990000;'>" . ($_POST['q5_yes']) . "</td></tr>";
$message .= "</table>";

$message .= "<tr><td><div style='border-bottom: 1px dashed #CCCCCC;'></td></tr>";
$message .= '<table rules="all" style="border-color: #FFF;" cellpadding="5">';
$message .= "<tr><td width='400'><strong>How did you hear about us?</strong> </td><td style='color: #990000;'>" . ($_POST['hear']) . "</td></tr>";
$message .= "</table>";
$message .= "</table>";
$message .= "</body></html>";

Link to comment
Share on other sites

I am not entirely sure where I should put this. Is this correct?

 

$disease =$_POST['disease'];
$message .="<tr><td>"; 
foreach ($disease as $issue) {
echo "<pre>";
print_r($results);
echo "</pre>";
}
$message .="</td></tr>";

Link to comment
Share on other sites

Okay I must be doing something wrong.

 

I have nothing but the error  :S

 

Here is what I have

 

$disease =$_POST['disease'];

$message .="<tr><td>";

echo "<pre>";

print_r($results);

echo "</pre>";

foreach ($disease as $issue) {

}

$message .="</td></tr>";

Link to comment
Share on other sites

If he can see the checkboxes in the form he has the results, simply looking at the html source code of the form page when loaded will show the variables outputted for each $results, $results doesnt get processed, the generated checkboxes from the results do.

 

at the top of the form processing I would do this

 

$disease=$_POST['disease'];
echo "<pre>";
print_r($disease);
echo "</pre>";

to see what values are passed for processing

 

Edit: are the checkboxes generated actually inside your form? can you attach a copy of the code so we can see the full layout of your methods

 

Link to comment
Share on other sites

when you submit your form are you ticking any of the disease boxes?,

we will just modify the code a bit more like this

 

if (isset($_POST['disease']) && is_array($_POST['disease'])) {
$disease=$_POST['disease'];
$message.="<tr><td>";
foreach ($disease as $issue) {
     $message.="Checked disease is $issue<br/>";
}
$message.="</td></tr>";
}

Link to comment
Share on other sites

Thats why it is giving you the error, what I just posted should fix it, the reason for the error was when you first loaded the form your message variable gets created, this should not really happen until after you submit the form, because of this it is looking for the disease array that is not yet created because you have not submitted the form yet. you need to move this

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 

to the top of your page before you start the message variable for your email, I would place this above the /* Moderators Confirmation */ part.

Link to comment
Share on other sites

oops just noticed we will still need the $keyID part in the foreach loop like this

 

if (isset($_POST['disease']) && is_array($_POST['disease'])) {
$disease=$_POST['disease'];
$message.="<tr><td>";
foreach ($disease as $keyID => $issue) {
     $message.="Checked disease is $issue<br/>";
}
$message.="</td></tr>";
}

Link to comment
Share on other sites

Thats great! Thank you

 

One last thing if you dont mind.

 

On success I have the script display a success page, and the same for error.

 

I use this:

print "<meta http-equiv=\"refresh\" content=\"0;URL=consult-success\">";

 

When you submit, it briefly flashes the form again from the top and then redirects. Is the code I am using a good way to forward to another page?

 

Thanks

Link to comment
Share on other sites

better to use header redirects

 

print "<meta http-equiv=\"refresh\" content=\"0;URL=consult-success\">";
    	} else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=consult-tryagain\">";

 

would become

 

        header("Location: consult-success.php");
        exit();
    	} else {
header("Location: consult-tryagain.php");
exit();

 

thats if your pages are php pages otherwise change .php to .html or .htm if that is the extension you are using for those pages

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.