Jump to content

Help me with basic script


codeboy89

Recommended Posts

Here is the html form you need:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>BMI Calculator</title>
</head>

<body>

<form action="bmi.php" method="post">
Enter Your Height (Inches) <input name="height" type="text" size="7" />
<br />
<br />
Enter Your Weight (Pounds) <input name="weight" type="text" size="7" />
<br />
<br />
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

 

and here is the php code you need:

<?php

$height = $_POST['height'] ;
$weight = $_POST['weight'] ;

?>

<?php

$bmih = $height * $height ;
$bmiw = $weight/$bmih ;
$bmiw *= 703 ;
echo "Your BMI (Body Mass Index) is " . number_format($bmiw , 2 , '.', ',') . "." ;
echo "<br />" ;
echo "<ul>" ;
echo "<li>Normal weight = 18.5-24.9</li>" ;
echo "<li>Overweight = 25-29.9</li>" ;
echo "<li>Obesity = BMI of 30 or greater</li>" ;
echo "</ul>" ;

?>

 

You should name the html form "bmi.html" and the php form should be named "bmi.php". Just copy and paste these into a file and save them with the names above. The script will calculate your BMI (Body Mass Index). It uses really basic PHP operators and functions. Hope this helps you.

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.