Jump to content

Recommended Posts

Help!

 

Fatal error: Unsupported operand types in /net/fsstud.itu.dk/export/stud/www/e2010/DSDS/arhe/incomplete/ps5/bmi2.php on line 29

 

THIS IS THE PROBLEM LINE: $bmi = $vaegt / (($hoejde/100) * ($hoejde/100));

 

Here is my code...any ideas what's wrong?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

 

      // faste variabler

        $vaegt = $_REQUEST['vaegt'];

        $hoejde = $_REQUEST['hoejde'];

     

     

        if ( preg_match_all('/^[0-9]{2}$|^[0-9]{3}$/', $vaegt, $hoejde))

        {

 

       

       

       

        // udskriv variabler

        echo "Vægt: $vaegt kg.";

        echo "<br />";

        echo "Højde: $hoejde cm.";

        echo "<br />";

       

        // udregn BMI

        $bmi = $vaegt / (($hoejde/100) * ($hoejde/100));

       

        // udskriv BMI

        echo "Dit BMI er $bmi<br />";

       

        // condition - hvad er BMI

        if ($bmi < 20.0 ) {

            echo "Dit BMI er for lavt.";

        }

        elseif ( $bmi < 25.0 ) {

            echo "Dit BMI er normalt.";

        }

        else {

            echo "Dit BMI er for højt.";

        }}

             

           

        //Hvis man ikke indtaster et tal, genereres et tilfældigt tal

        else  {

        echo "Indtast vægt i kilo og/eller højde i centimeter (fx. 65 - 170)";

       

           

           

       

          }   

       

       

?>

 

</body>

</html>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/215487-fatal-error-unsupported-operand-types/
Share on other sites

Change this line:

if ( preg_match_all('/^[0-9]{2}$|^[0-9]{3}$/', $vaegt, $hoejde))

 

To

if ( preg_match('/^[0-9]{2}$|^[0-9]{3}$/', $vaegt) && preg_match('/^[0-9]{2}$|^[0-9]{3}$/', $hoejde))

 

The syntax for preg_match(_all) is preg_match  ( string $pattern  , string $subject  [, array &$matches  [, int $flags  [, int $offset  ]]] );

 

It doesn't support multiple $subjects to compare against.

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.