parse error no for each

Asked

Viewed 22 times

0

I don’t know why that parse error in my foreach. Follows the code :

<?php

if (isset($_GET["submit"])){

}

$form =

foreach ($_GET["cimc"] as $form) {
    $peso ==  $_GET['peso'];
    $altura == $_GET['altura'];

    if (isset($peso)) {
        $imc = ($peso /( $altura * $altura));
    }
}

?>
  • Greetings, earthling. What would that be $form = lost in your code?

  • greetings, that $form = in case it was unintentionally, already removed and continues the same error

  • Please do the [tour] and read the [Ask] guide. Search the [Edit] question and add exactly what the error message is. Except you have used == for attribution rather than =, I couldn’t reproduce the "parser error" you quoted.

  • Parse error: syntax error, Unexpected 'foreach' (T_FOREACH) in /var/www/html/main/library/imc.php on line 31 would be the error

  • That would give with the $form there. If you got out, there’s no reason to make the mistake yet.

  • Notice: Undefined index: cimc in /var/www/html/main/biblioteca/imc.php on line 31 Warning: Invalid argument supplied for foreach() in /var/www/html/main/biblioteca/imc.php on line 31 ?>

Show 1 more comment

1 answer

0

Try to verify the existence of all variables and their type

 if(isset($_GET["cimc"]) && is_array($_GET["cimc"])){
        foreach ($_GET["cimc"] as $form) {
            if(isset($_GET['peso']) && isset($_GET['altura'])) {
                $imc = ($_GET['peso'] /( $_GET['altura'] * $_GET['altura']));
            }else{
                echo "Não temos: ";
                echo (isset($_GET['peso'])) ? "a altura": "o peso";
            }
        }
    }else{
        echo (isset($_GET["cimc"])) ? '':'Não temos $_GET["cimc"]';
        echo (is_array($_GET["cimc"])) ? '':'$_GET["cimc"] Não é array';
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.