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

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.

Member Avatar for diafol

Ouch!

<!--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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.