我是PHP新手,我正在做一些简单的练习,试图完全理解我学到的每一件事.我自信地输出从表单输入的数据,但对于这个特殊的练习,我看不出我错在哪里.表单当前正在输出"1".
我正在try 建立一个BMI计算器,非常感谢您的帮助,提前谢谢您.
我的表单
<?php
return "
<p>Calculate your BMI</p>
<form method='post' action='index.php?page=process-bmi'>
<p>Please enter your height and weight to calculate your BMI</p>
<label for='height'>Height</label>
<input type='text' id='height' name='height'>
<label for='weight'>Weight</label>
<input type='text' id='weight' name='weight'>
<input type='submit' value'Submit' name='bmi-submitted'>
</form>";
我的php是
<?php
$bmiSubmitted = isset($_POST['bmi-submitted']);
if ($bmiSubmitted) {
$weight = $_POST['weight'];
$height = $_POST['height'];
$output = bmi($weight, $height);
}
function bmi($weight, $height) {
$bmi = $weight/($height*$height);
$response = "<p>Your bmi is $bmi</p>";
return $response;
}
?>