Using two $_POST Function / Switch () statements, second does not work.


Posted on 16th Feb 2014 07:03 pm by admin

Hi all. I’m new to php and am having a problem getting $_POST Function / switch () to work. I am coding a registration form. I ask the user a Yes/No question. Depending on the answer I have an Include () bring in the coding for the next step of the registration process, which also has a Yes/No question. I am using submit buttons for the user to give me the answers.

The first $_POST Function / switch () works and will include () the proper coding. The second $_POST Function / switch () does not work.

Both are essentially the same coding with just the variable name changed.

This is the coding used:

<form action="register.php" method="post" name="regForm" id="regForm">
//
HTML in between, input user first name / last name
//
(This works)

// 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?



// This is the submit buttons

<input type="submit" name="agent" value="No">&nbsp;&nbsp;

<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;
}

?>

Once the above Yes/No is executed it brings in:

(This does not work)

// Asking if user want to sign up for foreclosure list

<?php

$forlst = " ";

if (!isset($_POST['forlst']))
{
//If not isset -> set with dummy value
$_POST['forlst'] = " ";
}

?>
<table align = "center" border="5" cellpadding="3" cellspacing="0">

<col width="430" >

<tr align = "center">

<td>

Would you like to receive our weekly foreclosure list (by email)



//This is the submit buttons

<input type="submit" name="forlst" value="No">&nbsp;&nbsp;

<input type="submit" name="forlst" value="Yes">

</td>

</tr>

</table>

// Yes / No switch

<?php

$forlst = $_POST['forlst'];

switch( $forlst ) {
case 'No':
include ("register_4.php");
break;
case 'Yes':
include ("register_4.php");
break;
}

?>

What am I doing wrong? Do I need to some how clear the POST before I use the function again? If so, how do I do it?

No comments posted yet

Your Answer:

Login to answer
273 Like 18 Dislike
Previous forums Next forums
Other forums

Firewall / visited websites logger
Hi. I have a firewall implementation and I want to log all the websites visited on the machine. S

is this the proper use of mysql_real_escape_string() to prevent sql injections?
i was wondering is this the proper use of mysql_real_escape_string() to prevent sql injections? any

simplexml and xpath - Need some help
Hello,

I am trying to parse an xml which comes back from Amazon and I am trying to know how m

gmdate() - want 1 hr before time
Hi,
I am using php gmdate().
Now I am entering all dates in my dbase using gmdate("Y-m-d

Error with login script
I am getting an error with my login script:

Error:
Code: Warning: Cannot modify header inf

Simple MySQL script is not working
Hey guys,

Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly

Why doesn't this work? (SSH2)
This is my script:

Code: <?php
$connection = ssh2_connect('213.251.167.109', 22);

Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,

Its been a while, I know. Use to love coming here to answer peoples questions, but

If a record matches an existing record do nothing
So I don't know if I should put this here or in mysql, but what my script is for is for people to ad

Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I wa

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash