Jump to content

If statement with Numbers


tarleton

Recommended Posts

Hello.

Here is my statement:

if ($bmi = < 18.5)
	echo "You are Underweight" ;
elseif ($bmi = > 18.5< 24.9)
	echo "You are Normal Weight" ;
elseif ($bmi = > 25< 29.9)
	echo "You are Overweight" ;
elseif ($bmi = > 30)
	echo "You are obese" ;

?>

 

But I get  Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\W06\bmi.php  on line 40

FYI Line 40 =

if ($bmi = < 18.5)

 

I've looked at examples on Google and yet they seem to look the same as this what am i doing wrong?

Link to comment
Share on other sites

use the && for a double comparison

elseif ($bmi <= 18.5 && $bmi <  24.9)

and

=< will throw a unexpected '<' error

=>will throw an T_DOUBLE_ARROW error

use >= or <= instead

its "greater than or equal to" or "less than or equal to"

 

 

HTH

Teamatomic

 

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>bmi.php</title>
</head>
<?php
$name = $_POST['name'];
$weight = $_POST['weight'];
$height = $_POST['height'] ;
?>
<body>
<?php 
echo "<table>
<tr>
<td>Name:</td>
<td>$name</td>
</tr>
<tr>
<td>Weight:</td>
<td>$weight</td>
</tr>
<tr>
<td>Height:</td>
<td>$height</td>
</tr>";
echo "</table>";
?>

<?php
$bmi = ($weight)*($weight) ;
$bmi = ($bmi)/($weight);
echo "$name, your BMI is $bmi <br>" ;


//Open the file which order will be written to.
$file = fopen("$name.txt","wr");
//Write the string to the file
echo fwrite($file,"Name: $name , Weight: $height , Height: $height , BMI: $bmi");
fclose($file);

if ($bmi <= 18.5)
	echo "You are Underweight" ;
elseif ($bmi >= 18.5 && $bmi <= 24.9)
	echo "You are Normal Weight" ;
elseif ($bmi >= 25 && $bmi <=  29.9)
	echo "You are Overweight" ;
elseif ($bmi >= 30)
	echo "You are obese" ;

?>

</body>
</html>

Above is my code fixed and thankyou for your help. A question question however why when I print this does it show the number of characters written to the text file?

 

Link to comment
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.