$_POST doesn’t work?

Asked

Viewed 114 times

0

I need to create another page for the if(isset($_POST['n'])){$n= $_POST['n'];} checks if the user entered some value and submitted it in the form

Form

<html>
    <head>
        <title>Divisão</title>
    </head>
    <body>
        <form method="POST" action="calculo.php">
            <h1> Digite um numero: </h1> <input type="text" name="n"/>
            <input type="submit" value="confirmar"/>
        </form>
    </body>
</html>

Page calculus.php

<?php
class controlador{
    private $n;

    function getN(){
        return $this -> n;
    }
    function setN(){
        $this -> n = $n;
    }

if(isset($_POST['n'])){//verifica se o usuario digitou algum valor e submeteu no form.
    $n= $_POST['n'];

    // DIVISIVEL POR 10
    if ($n %  10 ==  0)
    {
        echo $n . " é divisível por 10 =  " . $n/10 . "<br>";}
    else
    {
        echo $n . " nao divisível por 10 <br>";
    }

    //DIVISIVEL POR 5
    if ($n %  5 ==  0)
    {
        echo $n . " é divisível por 5 =  " . $n/5 . "<br>";
    }
    else
    {
        echo $n . " nao divisível por 5 <br>";
    }
    // DIVISIVEL POR 2
    if ($n %  2 ==  0)
    {
        echo $n . " é divisível por 2 =  " . $n/2 . "<br>";
    }
    else
    {
        echo $n . " nao divisível por 2 <br>";
    }

}
else echo "informe um numero"; //quando não digitar nada
?>
  • 1

    There are some mistakes in your class controlador it is important to read the documentation: Classes and Objects. Does your class have a lost condition inside it or was it just time to put it here? and yet it remains to close class controlador {&#xA;// código&#xA;}

  • Vixi I’m no longer understand anything. Lost condition? is that the teacher asked to use the methods of object orientation in the execise.

  • It wasn’t for the condition if(isset($_POST['n'])){ be within a method ? When you send the form returns some error on the page ?

  • It even seems to me that you got confused in the construction of the class as @Noobsaibot indicated. The ideal is to review even the matter of classes and objects and come back later when you already know minimally well how those parts work.

  • the $this and the -> have to be together $this-> and the n within the ifwould have to be $this->n For all this it would not need to be object oriented

No answers

Browser other questions tagged

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