sawade Posted August 10, 2009 Share Posted August 10, 2009 [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. Link to comment https://forums.phpfreaks.com/topic/169673-solved-php-parse-error-echo-an-array-issue/ Share on other sites More sharing options...
GingerRobot Posted August 10, 2009 Share Posted August 10, 2009 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 />"; } Link to comment https://forums.phpfreaks.com/topic/169673-solved-php-parse-error-echo-an-array-issue/#findComment-895105 Share on other sites More sharing options...
sawade Posted August 10, 2009 Author Share Posted August 10, 2009 Perfect. Thank you for the extra set of eyes. Link to comment https://forums.phpfreaks.com/topic/169673-solved-php-parse-error-echo-an-array-issue/#findComment-895113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.