I've already made calculation for BMI and I can update height(will update weight soon) if user getting taller or shorter. The problem is, after I already update the height I cannot update BMI and BMI STATUS(underweight, normal, obese) which is a big problem for me..
This is my coding for php
if(!isset($_SESSION['user']))
{
header("Location: PHOME.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
if(isset($_POST['updateH']))
{
$height = $_POST['height'];
$weight = $_SESSION['user'];
$sex = $_SESSION['user'];
$bmiresult = $_SESSION['user'];
$bmi = $weight/(($height/100)*($height/100));
if ($sex=="female")
{
if ($bmi <= 19)
$bmiresult="underweight!";
else if ($bmi>19 && $bmi<= 25)
$bmiresult="normal";
else if ($bmi > 25 && $bmi<= 30)
$bmiresult="overweight!";
else if ($bmi>30)
$bmiresult="OBESE!";
}
else if ($sex=="male")
{
if ($bmi <= 20)
$bmiresult="underweight!";
else if ($bmi>20 && $bmi<= 25)
$bmiresult="normal";
else if ($bmi > 25 && $bmi<= 30)
$bmiresult="overweight!";
else if ($bmi>30)
$bmiresult="OBESE!";
}
$sql = "UPDATE users SET height = $height, weight = $weight,
bmi = $bmi, bmiresult = '$bmiresult'
WHERE user_id=" . $_SESSION['user'];
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "<script type='text/javascript'>alert('Update Successfully!')</script>";
} else {
echo mysql_error();
}
}
This is my form which I am using bootstrap
<form method="post" action="<?php $_PHP_SELF ?>">
<h3> Height : <?php echo $userRow['height']; ?> cm</h3>
<input type="text" class="small" name="height" id="height" placeholder="Update Height CM"/>
<button type="submit" class="btn btn-warning" name="updateH"> UPDATE </button>