Html form is not calling php

Asked

Viewed 56 times

0

I’m making a simple php script that receives the login data from an html form, only apparently html is not calling the php script.

snippet of html code:

<form action="index.php" method="post">
  Login:<br>
  <input type="text" name="userr"><br>
  <br>
  Senha:<br>
  <input type="password" name="senha"><br>
  <br>
  <input type="submit" value="OK"><br>
</form>

Excerpt from php code:

ini_set("display_erros", 1);
echo "passou 1";
if($_Server['REQUEST_METHOD'] == 'POST'){  
    echo "passou 2";
...

What’s wrong with that code? ps: neither of these two Echos are printing something. The php and html code are in the same file "index.php".

  • What is your http server?

  • Apache, httpd..

  • Hello John already tried to use the # there in the action how to deal with the same file can be used # does not need to put the name of the file itself. example: <form action="#" method="post">

1 answer

0


Try to do it that way:

<form action="index.php" method="POST">
    <div>
        <label>Login:</label>
        <input type="text" name="user"><br>
    </div>
    <div>
        <label>Senha:</label>
        <input type="password" name="senha"><br>
    </div>
    <div>
        <button type="submit">OK</button>
    </div>
</form>

<?php 
# Verificar se a requisição é valida em modo post
if ($_POST) {
    # Testar se o campo user foi enviado
    $user = (isset($_POST["user"])) ? $_POST["user"] : "Não informado";
    # Testar se o campo senha foi enviado
    $user = (isset($_POST["senha"])) ? $_POST["senha"] : "Não informado";

    # Mostrar os campos em um print formatado
    printf("Pessoa, %s com a senha %s", $_POST["user"], $_POST["senha"]);
}
?>

Browser other questions tagged

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