-1

Is there a way I can hide my IF/ELSE results unless the form has been submitted? At the moment when i visit the pge it auto outputs the else statement.

Here is my php:

$height =  $_POST['height']  / 100;
$weight = $_POST['weight'];

$bmi = $weight / $height;
$bmi = $bmi / $height;

$total = 
$_POST['Radios'] +
$_POST['Radios1'] +
$_POST['Radios3'] +
$_POST['Radios4'] +
$_POST['Radios5'] +
$_POST['Radios6'];


if($total >= 2 || $bmi > 22){
    $warning = 'Your ill';
} else {
    $safe = 'Your ok';
}

The php is above the html form I am unable to move it to another file(restricted).

PhpDude
  • 1,542
  • 2
  • 18
  • 33

1 Answers1

5

put it on

<?php 
if($_SERVER['REQUEST_METHOD']=='POST'){
 // YOUR CODES GOES HERE 
}
?>

Put this code the page you are submitting the form. So what is does if the http request is POST then it will run the code inside of it.

Hope the helps

pinoyCoder
  • 940
  • 7
  • 20