I am coding a registration page. In it I am asking a couple of Yes/No questions pulling the questions into the form with the include ( ) function. I am using two submit buttons (Yes/No) to get the answers from each question. I collect the value with a $_POST[‘’] function, have a switch statement to figure out what they chose and include ( ) function to bring in the correct PHP code depending on the users answer. In that next set of code is another Yes/No question that is loaded below the first question. It does not matter what answer the user chooses in the first (Yes/No) question because eventually the second question is asked.
The first Yes/No question works great. It goes through the $_POST[‘ ‘}, switch and triggers the proper include ( ). The second question loads and is shown in the browser along with the Yes/No input buttons, everything loads as it should.
Then it stops working correctly…
When you click on one of the Yes/No buttons on the second question all the code that was brought in with the last include ( ) disappears and I am back at the first question.
I put “echo 'List test'.$lstprop;” after the $lstprop = $_POST['lstprop']; statement in the second question. When the code first loads the “List test” (no value or "")shows in the browser. It disappears with the rest of the coding once a button is clicked on the second set.
It appears that the second set of Yes/No submit button are not working. The first set of Yes/No buttons are still active and will cycle through the POST [‘ ‘], switch, include ( ) again loading whatever the input was.
The coding is almost identical in both questions, only the variable names are changed.
Can someone tell me why this stops working correctly once the second question is loaded and how to fix it?
I took most of the HTML code out of this post. Code with HTLM can be found in attachment.
My code.
(First question (this works))
<form action="register.php" method="post" name="regForm" id="regForm">
/
/ There is HTML code in between asking for user information using <input>
/
<!-- asking if user is a real estate agent -->
<?php
$agent = " ";
if (!isset($POST['agent']))
{
//If not isset -> set with dummy value
$POST['agent'] = " ";
}
?>
<table align = "center" border="5" cellpadding="3" cellspacing="0">
<col width="430" >
<tr align = "center">
<td>
Are you a licensed Florida real estate agent?<br><br>
<!-- This is the submit buttons -->
<input type="submit" name="agent" value="No">
<input type="submit" name="agent" value="Yes">
</td>
</tr>
</table>
<!-- Yes / No switch -->
<?php
$agent = $_POST['agent'];
switch( $agent ) {
case 'No':
include ("register_3.php");
break;
case 'Yes':
include ("register_2.php");
break;
}
?>
(end of first question)
(Second question (this does not work))
<!-- asking if user wants weekly listings -->
<?php
$lstprop = " ";
if (!isset($POST['lstprop']))
{
//If not isset -> set with dummy value
$POST['lstprop'] = " ";
}
?>
<table align = "center" border="5" cellpadding="3" cellspacing="0">
<col width="430" >
<tr align = "center">
<td>
Would you like to receive our weekly property listings (by email)<br><br>
<!-- This is the submit buttons -->
<input type="submit" name="lstprop" value="No">
<input type="submit" name="lstprop" value="Yes">
</td>
</tr>
</table>
<!-- Yes / No switch -->
<?php
$lstprop = $_POST['lstprop'];
switch( $lstprop ) {
case 'No':
include ("register_4.php");
break;
case 'Yes':
include ("register_4.php");
break;
}
?>