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.