0

Pls advise, what is wrong with the PHP script:

<html>
<head>
<title>Calorie Calculation</title>
</head>
<body>
<?php
$calorie = ($_POST["fat"] * 9) / ($_POST["calories"] * 100);
?>
Welcome, $_POST["foodname"] contains:  <?php echo $calorie ."from fat" ;
echo "<br />";
{
if ($calorie > 30)
	echo ($_POST["foodname"]) 'contains $calorie % from fat <br />';
	echo ($_POST["foodname"]) 'exceeds the AHA recommendation';

else
	echo ($_POST["foodname"]) 'contains" $calorie "% from fat  <br />';
	echo ($_POST["foodname"]) 'is within the AHA recommendation of 30% calories from fat';

}

?>
</body>
</html>

Thanks,
Tony

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by almostbob
0

You might want to read your book or the tutorial or whatever you're using to learn PHP again because there are WAY too many things wrong with that script.

0
<!--doctype must be declared xhtml -->
<html>
<head>
<title>Calorie Calculation</title>
</head>
<body>
<?php
if (!$_POST['foodname']) { echo 'No food selected <br /> more error checking is required'; }
else {
if (!$_POST['calories'] == 0 ){ $calorie = ($_POST['fat'] * 9) / ($_POST['calories'] * 100); } //division by zero errors?
echo $_POST['foodname'].' contains: '.$calorie.' from fat<br />';
if ($calorie > 30) { echo $_POST['foodname'].' exceeds the AHA recommendation'; }
else { echo $_POST['foodname'].' is within the AHA recommendation of 30% calories from fat'; }
}
?>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.