Jump to content

Recommended Posts

1.) if statements not working it just outputs everything no matter what category you are in.

 

2.) displays 000.00 instead of 00.00

 

if any of you can  help me out i would be appreciative  ;D

 

<?php
$height= trim($_POST['height']);
$weight=trim($_POST['weight']);
$height=str_replace(',','',$height);
$height=str_replace('.','',$height);
$height=strip_tags($height);
$weight=strip_tags($weight);
$weight=str_replace(',','',$weight);
$weight=str_replace('.','',$weight);

if ($_POST['height']||$_POST['weight']=="true")
{ 
$weighttwo=$weight*100;   

$total=$weighttwo/$height;}
if($_POST['weight']=="") {$error['weight']="<font color=red>Please enter a weight!</font>";} else {unset($error['weight']);}

if($_POST['height']=="") {$error['height']="<font color=red>Please enter a height!</font>";} else {unset($error['height']);} 


if($error) {?>

<form method="POST">

<b>Height(inches):</b><input name="height" type="text" size="3"><?php if ($_POST) { echo $error['height'];} ?><b>Weight(lbs.):</b><input name="weight" type="text" size="3"><?php if ($_POST) { echo $error['weight'];} ?>
<input type="submit" name="Calculate!" value="Calculate!">

</form>
<?php } else{
if($total<18) {
$underoutput= sprintf('%01.2f',$total);
echo"<font color=red>
You're Underweight! Youre BMI is:$underoutput</font>";
}
if($total>18 || $total<25) { 
$healthyoutput= sprintf('%01.2f',$total);
echo"<font color=green>
You're Healthy! Youre BMI is:$healthyoutput</font>";
}
if($total>25 || $total<30) {
$overweightoutput= sprintf('%01.2f',$total);
echo"<font color=orange>
You're Overweight! Youre BMI is:$overweightoutput</font>";
}

if($total>30) { echo "<font color=red>You Are Overweight Please seek Immediate Medical Help!</font>";}




}?>


Link to comment
https://forums.phpfreaks.com/topic/153955-solved-form-problems/
Share on other sites

1) You're using || instead of &&

 

2) The answers are coming out as numbers above 100.  I think your formula is wrong, see here: http://www.whathealth.com/bmi/formula.html

 

3) You may want to reorganize your code entirely, it's very confusing.

 

4) Your validation at the top could be condensed.  intval

Link to comment
https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809142
Share on other sites

yeah i fixed it i didnt double the inches it works now. however it is doing

 

 

"you are Healthy your BMI is: 25.00"

You are over weight  your BMI is: 25.00"

 

how do i make it display your BMI is 25 you are overweight

 

your BMI is 24.00 you are healthy"

Link to comment
https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809189
Share on other sites

$total = ($weight / ($height * $height)) * 703;
$output = sprintf('%01.2f',$total);
switch($total)
{
    case ($total < 18):
    $msg = "<font color=red>You're Underweight! Youre BMI is:$output</font>";
    break;

    case ($total >= 18 && $total < 25):
    $msg = "<font color=green>You're Healthy! Youre BMI is:$output</font>";
    break;

    case ($total >= 25 && $total < 30):
    $msg = "<font color=orange>You're Overweight! Youre BMI is:$output</font>";
    break;

    default:
    $msg = "<font color=red>You Are Overweight Please seek Immediate Medical Help!</font>";
    break;
}
echo $msg;

Link to comment
https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809214
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.