title: Store javascript variable in mysql database
body: <p>I'm very new to web design and I am struggling with storing a javascript variable in my database.</p>
  
  <p>I have a simple page with an HTML form that has textboxes for height/weight/age/gender and a submit button that calls a javascript function that does some calculations to determine if the user is under or overweight and then returns how many calories they should consume a day to be the correct weight for their BMI.</p>
  
  <p>Here is the javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function bmiCalc()
  {
      var height=document.getElementById('height box').value,
      weight=document.getElementById('weight box').value;
  
      weight/=2.2;
      height/=39.37;
  
      BMI=Math.round(weight/(height*height));
      alert("Your BMI is :"+BMI);
  }
  
  function calorieIntake()
  {
      var height=document.getElementById('height box').value,
      weight=document.getElementById('weight box').value,
      age=document.getElementById('age box').value,
      gender=document.getElementById('gender box').value;
  
      if(gender=="male" || gender=="Male")
      {
          if(23&lt;BMI &amp;&amp; BMI&lt;25)
          {
              calories=Math.round((66+(6.23*weight)+(12.7*height)-(6*age)));
              alert("You are considered normal weight and should therefore consume: " +calories+" calories a day. This calorie intake will ensure that you remain the same weight");
          }
  
          else if(BMI&lt;23)
  
          {
              calories=Math.round((66+(6.23*weight)+(12.7*height)-(6*age)+500));
              alert("You are considered under-weight, and should therefore consume: " +calories+" calories a day. This calorie intake will cause you to gain one pound a week");
          }
  
          else if(BMI&gt;25)
          {
              calories=Math.round((66+(6.23*weight)+(12.7*height)-(6*age)-500));
              alert("You are considered over-weight and should therefore consume: " +calories+" calories a day. This calorie intake will cause you to lose one pound a week");
          }
      }
  
      else if(gender=="female" || gender=="Female")
      {
          if(18.49&lt;BMI &amp;&amp; BMI&lt;24.9)
          {
              calories=Math.round(655+(4.35*weight)+(4.7*height)-(4.7*age));
              alert("You are considered normal weight and should therefore consume: "+calories+" calories a day. This calorie intake will ensure that you remain the same weight");   
          }
  
          else if(BMI&lt;18.49)
  
          {
              calories=Math.round((655+(4.35*weight)+(4.7*height)-(4.7*age)+500));
              alert("You are considered under-weight, and should therefore consume: " +calories+" calories a day. This calorie intake will cause you to gain one pound a week");
          }
  
          else if(BMI&gt;24.9)
          {   
              calories=Math.round((655+(4.35*weight)+(4.7*height)-(4.7*age)-500));
              alert("You are considered over-weight and should therefore consume: " +calories+" calories a day. This calorie intake will cause you to lose one pound a week");
          }
      }
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>and here is my form:</p>
  
  <pre><code>&lt;form&gt;
  &lt;p&gt;Enter your height(in inches):&lt;/p&gt;&lt;input type="text" id="height box"&gt;
  &lt;p&gt;Enter your weight(in pounds):&lt;/p&gt;&lt;input type="text" id="weight box"&gt;
  &lt;p&gt;Enter your age(in years):&lt;/p&gt;&lt;input type="text" id="age box"&gt;
  &lt;p&gt;Enter your gender(male/female):&lt;/p&gt;&lt;input type="text" id="gender box"&gt;
  &lt;input type="button" value="Your BMI:" id="button1" onClick="bmiCalc()"&gt;
  &lt;/input&gt;
  &lt;input type="button" value="Suggested Calorie Intake:" id="button2" onClick="calorieIntake()"&gt;
  &lt;/input&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What I want to do is take the 'calories' variable and store it in my MySQL database. I understand I need to somehow pass the javascript variable to a php variable but I don't have any idea how to do that. What is the simplest way to go about doing this?</p>