Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!