The page only displays the Else message. if doesn’t work and I don’t know what the problem with that simple code is anymore

Asked

Viewed 40 times

-3

<?php

    if ($_POST) {

        $nome = $_POST['nome'];
        $telefone = $_POST['telefone'];
        $logradouro = $_POST['logradouro'];
        $numcasa = $_POST['numcasa'];
        $bairro = $_POST['bairro'];
        $cidade = $_POST['cidade'];
        $foto = $_POST['foto'];
        $texto = $_POST['texto'];

        $mensagem = "";
        $mensagem.= "<b>Você denunciou um ponto de foco do Aedes Aegypti.</b>";
        $mensagem.= "<b> Obrigado </b>".$nome."<b> por ajudar no combate a Dengue..</b>";
    }

    else {
        $mensagem = "<div class='erro'>";
        $mensagem.= "<b>Favor preencer os dados corretamente.</b>";
        $mensagem.= "</div>";
    }

?>

<!DOCTYPE html>
<html>
<head>
        <link rel="stylesheet" type="text/css" href="stylesheet/text.css">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
        <title>Sistema Zer@ Dengue</title>
    </head>
<body>

    <div class="nav">
            <nav>
                <ul class="nav justify-content-end">
                    <li class="nav-item">
                        <a class="btn btn-light" href="#"><h5>Início</h4></a>
                    </li>
                    <li class="nav-item">
                        <a class="btn btn-light" href="#"><h5>Orientações</h5></a>
                      </li>
                    <li class="nav-item">
                        <a class="btn btn-light" href="#"><h5>sobre</h5></a>
                    </li>
                </ul>
            </nav>
        </div>

    <header class="header">



        <div class="tema">
            <h1>Bem vindo ao Zer@ Dengue</h1>
            <h2>O sistema de proteção contra o Aedes Aegypti</h2>   
        </div>


    </header>

    <main>
        <div class="resultado">
                <div class="erro">
                    <?php
                    echo $mensagem;
                    ?>
                </div>
        </div>
    </main>

    <footer>
        <p>&copy; Secretaria de Saúde. Todos os direitos reservados.</p>
    </footer>
</body>
</html>

</body>
</html>
  • How is the POST request made for this page?

  • Brother, first we need to see your form. So we can see how this data is coming in your PHP and how this $_POST is being filled in. From what you said in the question, it seems that your $_POST is not configured. With this your code enters the ELSE.

1 answer

0

the correct test is like this:

if ($_SERVER['REQUEST_METHOD'] == 'POST') 

So it checks if the page was triggered by the post method (i.e., by the form).

  • Perfect. although also had a detail in html. Thank you.

Browser other questions tagged

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