darkfreaks Posted April 14, 2009 Share Posted April 14, 2009 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 <?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>";} }?> Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/ Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809142 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 thanks for the correction the formula was way off anyhow the only problem i am having now is the statements not displaying right any thoughts ??? Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809146 Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 1) You're using || instead of && Post updated code otherwise? Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809147 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 i changed to && and it doesnt make a licking difference Note: i need it outputed using sprint f so it says 00.00 no matter what Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809148 Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 Post updated code otherwise? Also, why would you want to lie about the math? Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809150 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 i noticed i didnt double the inches so i did <?php $total= $weighttwo/$height*2 //outputs 0000.00 ?> if i dont double the inches i get something like 000.00 :-X Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809159 Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 I'm pretty sure the formula is: [tex]BMI = \left(\frac{weight In Pounds}{height In Inches^2}\right)*703[/tex] http://www.wikihow.com/Calculate-Your-Body-Mass-Index-(BMI) $total = ($weight / ($height * $height)) * 703; right? Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809175 Share on other sites More sharing options...
darkfreaks Posted April 14, 2009 Author Share Posted April 14, 2009 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" Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809189 Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 $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; Quote Link to comment https://forums.phpfreaks.com/topic/153955-solved-form-problems/#findComment-809214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.