PHP page does not receive data via POST

Asked

Viewed 198 times

-2

I’m having a problem, for some reason my script does not receive data from a form, however if I send the form to the same page, it gets.

Following form:

<form method="POST" action="/pjf/API/login.php" class="form-signin bg-white rounded border shadow p-5" id="formulario">
          <div class="text-center mb-4">
            <h1 class="h3 mb-3 font-weight-normal">BEM-VINDO</h1>
            <p>Insira seus dados de login e senha corretamente.</p>
          </div>

          <div class="form-label-group">
            <input type="text" id="inputEmail" name="login" class="form-control btn-circle" placeholder="Login" required autofocus>
            <label for="inputEmail">Login</label>
          </div>

          <div class="form-label-group">
            <input type="password" id="inputPassword" name="pass" class="form-control btn-circle" placeholder="Senha" required>
            <label for="inputPassword">Senha</label>
          </div>

          <button class="btn btn-lg btn-outline-primary btn-block btn-circle" type="submit" name="submitt">ENTRAR</button>
          <p class="mt-5 text-muted text-center">Login Teste - 2020</p>
        </form>

Follows PHP code

<?php
  echo $_POST['login'];
?>

I know the data is sent because if I take the action, the form page itself receives and shows the data.

  • As to the question, enter the directory structure.

  • The folder pjf would be the root directory. The form page is the following structure: 'pjf/log-in/auth/13350044395f1e6bc5ac5fb/l/0/'. The PHP receiver page is in the following structure: 'pjf/API/login.php'.

  • Dude, there are too many variables left to come up with! But I suggest putting the full URL in the action: 'http://................ /API/login.php"

2 answers

-1

Friend if u do not post the directory path correctly your post will not work, your action is action="/pjf/API/login.php", but vc informs the following directory structure pjf/log-in/auth/13350044395f1e6bc5ac5fb/l/0/login.php, assuming the post target would be in the folder 0/ and supposing that your form file was in the root folder your action would be action="log-in/auth/13350044395f1e6bc5ac5fb/l/0/login.php". I hope I’ve helped...

-1

The problem appears to be the path used in your action. When you start using the "/" character, this indicates the root of your server. That is if you are running on localhost, literally he will search in http://localhost/pjf/API/login.php

You have two options. The first work with the relative path is without the character "/" at first, so from the directory in question he will look in the way. Let’s assume your form is in "http://localhost/system/index.php", and the action point to "pjf/API/login.php", your literal path will be "http://localhost/system/pjf/API/login.php".

The second option would be to put the action with the full path, for example "http://localhost/system/pjf/API/login.php" so there would be no error. I stress that this second option would only be smart using a function to return the path, because if you were to play this to a server in the cloud, you would have to change the localhost everywhere you use that term. Prefer to use the relative path, first option given.

Browser other questions tagged

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