title: Writing a BMI calculator with PHP
body: <p>I'm trying to use what I've learned in PHP in this BMI calculator.
  I checked the code for errors in a PHP syntax checker and it's clean, but I'm getting an error when I render the page in a browser. The error is where $bmi is declared.</p>
  <p>Any tips to writing better code is appreciated.</p>
  <pre><code>      &lt;form class=&quot;&quot; action=&quot;index.php&quot; method=&quot;post&quot;&gt;
        Name:  &lt;input type=&quot;number&quot; name=&quot;name&quot; value=&quot;&quot;&gt;&lt;br&gt;
        Age:  &lt;input type=&quot;number&quot; name=&quot;age&quot; value=&quot;&quot;&gt;&lt;br&gt;
        Height:  &lt;input type=&quot;number&quot; name=&quot;height&quot; value=&quot;&quot;&gt;&lt;br&gt;
        Weight:  &lt;input type=&quot;number&quot; name=&quot;weight&quot; value=&quot;&quot;&gt;&lt;br&gt;
        &lt;input type=&quot;submit&quot; name=&quot;sumbit&quot; value=&quot;Submit&quot;&gt;
        &lt;/form&gt;
  
  
        &lt;?php
        $name = $_POST[&quot;name&quot;];
        $age = $_POST[&quot;age&quot;];
        $height = $_POST[&quot;height&quot;];
        $weight = $_POST[&quot;weight&quot;];
  
        if ($weight &amp;&amp; $height) {
  
            function greeting() {
               $bmi = $weight / ($height * $height);####Error is in this line
              echo &quot;Hello $name, your age is $age. You weigh $weight kg and your height in meters is $height &lt;br&gt; Your BMI is $bmi&quot;;
              #$GLOBALS[&quot;height&quot;] = $height;
              #$GLOBALS[&quot;weight&quot;] = $weight;
            }
              greeting();
          }
        ?&gt;
        &lt;br&gt;&lt;br&gt;
        &lt;?php
          if ($bmi &lt; 18) {
           echo &quot;You are underweight.&quot;;
         } elseif ( $bmi &gt;= 18 &amp;&amp; $bmi &lt; 25 ) {
           echo &quot;You are normalweight.&quot;;
         } elseif ($bmi &gt; 25) {
           echo &quot;You are overweight.&quot;;
         }
         ?&gt;
  </code></pre>