Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Form data sent via POST method gets empty

I am posting the "user" variable to another page i.e. Survey.php as follows:

index.html

<form action="Survey.php" method="post" name="frm">
  <div><input type="text" name="user"></div>
  <div><input type="submit" value="Start" class="btn btn-primary btn-sm"></div>
</form>

I can access the "user" variable on Survey.php page on its first load. Now, because I have another form on this page as well, which posts data to itself.

Survey.php

$user = $_POST["user"];
echo 'this is '.$user;
$email = $_POST[email];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$sql = "INSERT INTO `test_db` (`user`, `email`) VALUES '$user', '$email');";
echo $sql;
}
<form action="survey.php" method="post">
  <div><input type="text" name="email"></div>
  <div><input type="submit" value="submit" class="btn btn-primary btn-sm"></div>
</form>

I am trying to send "user" and "email" together to the database now. What happens actually is that everytime I click on submit button of the survey.php page, the "user" variable gets empty.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You have to test your posts DATA and user Sesssion. In your PHP code, you can have something like that

<?php
session_start();
if(isset($_POST['user']))
  $_SESSION['user'] = $_POST['user'];
if(isset($_POST['email']))
  $_SESSION['email'] = $_POST['email'];
if(isset($_SESSION['user']) AND isset($_SESSION['email'])){
   $sql = "INSERT INTO `test_db` (`user`, `email`) VALUES '$_SESSION['user']', '$_SESSION['email']');";
  echo $sql;
}


If you don't want to use sessions, you can play with your form like this :

$user = $_POST["user"];
echo 'this is '.$user;
$email = $_POST[email];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$sql = "INSERT INTO `test_db` (`user`, `email`) VALUES '$user', '$email');";
echo $sql;
}
<form action="survey.php" method="post">
  <div><input type="text" name="email"></div>
  <div><input type="submit" value="submit" class="btn btn-primary btn-sm"></div>
  <input type="hidden" name="user" value="<?php echo $user; ?>">
</form>
about 4 years ago · Juan Pablo Isaza Relatório

0

You have $user and $email as variable then why are you putting them as strings? The below code should work -

$user = $_POST["user"];
echo 'this is '.$user;
$email = $_POST[email];
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$sql = "INSERT INTO `test_db` (`user`, `email`) VALUES '" . $user . "', '" . $email . "');";
echo $sql;
}
<form action="survey.php" method="post">
  <div><input type="text" name="email"></div>
  <div><input type="submit" value="submit" class="btn btn-primary btn-sm"></div>
</form>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda