Jump to content

[SOLVED] PHP Parse error: (echo an array issue)


sawade

Recommended Posts

[pre]This is the error I am receiving.

 

[10-Aug-2009 15:20:29] PHP Parse error:  syntax error, unexpected T_FOREACH in formtester.php on line 462

 

I recently changed my form from simply echo the data input into the form, now the echo data is formatted into a table. 

Before the change I had no errors with my code, now I have spent a few days debugging.  Here is the code.

 

I use the $history_list and $allergy_list variables in the email msg that is sent, imploding the array was the only way

I could get it to reflect properly in the email.

 

Thanks for the help![/pre]

 

$history = $_POST['history'];
$history_list = implode(", ",$_POST['history']);
$allergy = $_POST['allergy'];
$allergy_list = implode(", ",$_POST['allergy']);

echo '<tr>';
		echo '<th>Medical History:';
		echo '</th>';
		echo '</td>' . foreach ($history as $key) { echo "$key <br />"; }
		echo '</td>';
            echo '<th>Allergies';
		echo '</th>';
		echo '</td>' . foreach ($allergy as $key2) { echo "$key2 <br />"; }
		echo '</td>';
	echo '</tr>';

 

P.S. Please don't say to do this:  error_reporting(E_ALL ^ E_NOTICE);  I want to fix the script not ignore the errors.  Thanks.

On this line (and another below):

 

echo '</td>' . foreach ($history as $key) { echo "$key <br />"; }

 

You're trying to concatenate a string with a piece of code, you can't do that. These are separate statements, so need a semi-colon between them:

 

echo '</td>';
foreach ($history as $key) { echo "$key <br />"; }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.