tarleton Posted March 19, 2010 Share Posted March 19, 2010 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 https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/ Share on other sites More sharing options...
Zane Posted March 19, 2010 Share Posted March 19, 2010 the equal sign and the greater than sign have to form as one in order to be a .... united operator. So... instead of = > use => Also.. you have to specify each comparison. like $blahblah >= 25.5 AND $dfjsdklf Link to comment https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/#findComment-1028395 Share on other sites More sharing options...
teamatomic Posted March 19, 2010 Share Posted March 19, 2010 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 https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/#findComment-1028401 Share on other sites More sharing options...
tarleton Posted March 19, 2010 Author Share Posted March 19, 2010 <!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 https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/#findComment-1028409 Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 $file = fopen("$name.txt","wr"); wr is not a valid option, Look into r/r+ and w/w+ Link to comment https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/#findComment-1028413 Share on other sites More sharing options...
teamatomic Posted March 19, 2010 Share Posted March 19, 2010 Because you are echo'ing out fwrite. fwrite, as you know writes to a file, however, it returns the bytes written. so when you echo out fwrite you get the bytes written. so if !fwrite is the same as if fwrite<1 HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/195763-if-statement-with-numbers/#findComment-1028415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.