Coding Problem

Working through PHP5 & MySql Bible by Converse, Park & Morgan - Chapter 10.

[php]$message .= “

$exercise_type

”;
foreach ($per_exercise_info
as $exercise_name => $calories_burned) {
$message .= “

”.
ucfirst(“$exercise_name: $calories_burned calories

”);
$total_calories += $calories_burned;
}
}
if ($message == “” || $weight == 0) {
$message =

Did you enter your weight and at least one exercise?”;
}
else {
$message .=

Total calories burned: $total_calories

”;
}
// Now lay out the page
// --------------------
$page_str = <<< EOPAGE

Workout calculator handler (Math)

The workout calculator says: $message

EOPAGE; echo $page_str; ?>[/php]

Getting “Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\test(wc_handler_math.php on line 31”

Cannot fathom out why. There is an include file also which is not in the above code,

Brian

It would probably be a good idea to show the include file code, as line 31 on the php code you’re showing is HTML code; specifically .

Here is the code for the include file:

[php]<?php
// categories of exercise with associated calories per minute
// (not medically trustworthy because we made them up)
$exercise_info =
array(‘Aerobic exercise’ =>
array(‘biking/cycling’ => 9,
‘rowing’ => 8,
‘running’ => 14,
‘stairclimber’ => 6,
‘walking’ => 5),
‘Sports’ =>
array(‘basketball’ => 12,
‘ice hockey’ => 9,
‘soccer/football’ => 11,
‘table tennis’ => 7),
‘Strength training’ =>
array(‘calisthenics’ => 11,
‘weightlifting (light)’ => 9,
‘weightlifting (strenuous)’ => 13),
‘Stretching/flexibility’ =>
array(‘pilates’ => 5,
‘tai chi’ => 6,
‘yoga’ => 5)
);
?>[/php]

Your using thw wrong quotes you need to use " instead of “ otherwise php does not know what they are and treats it as raw text and generated the error.

Also looks like you calling the wronf variable in the foreach give this a try:

[php]$message .= “

$exercise_info

”;
foreach ($exercise_info as $exercise_name => $calories_burned) {
$message .= “

”.
ucfirst("$exercise_name: $calories_burned calories

");
$total_calories += $calories_burned;
}
if ($message == “” || $weight == 0) {
$message = “

Did you enter your weight and at least one exercise?”;
}
else {
$message .= “

Total calories burned: $total_calories

”;
}
// Now lay out the page
// --------------------
$page_str = <<< EOPAGE

Workout calculator handler (Math)

The workout calculator says: $message

EOPAGE; echo $page_str; ?> [/php]

I changed the code to read $message .= “

$exercise_info

”;

Prior to saving the file (before I first posted) I did a search & replace for curly quotes and cannot see any other instances of the dreaded curlys in the code.

Still get the same error

Brian

Sponsor our Newsletter | Privacy Policy | Terms of Service