• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

PHP if isset issue

I have a php page that has two forms on it.  The first form when submitted, you stay on the same page.   The first form has a place for you to enter an email address and pick a state from a select.  The second form also has a spot for your email address and also a place to choose a state from a select.  I want to populate email input and the state select with email that was entered earlier and the state that was selected.
First Form:
<select name="bike_state" id="bike_state" {sticky}>
			<div><option value="" style="display:none">Choose State</option></div>
			<?php
				$query = ee()->db->query('SELECT id, state FROM exp_state_rates');
				foreach ($query->result() AS $row)
				{
					echo '<option name="bike_state" class="option-center" value="'.$row->id.'" >'.$row->state.'</option>';	
				}
			?>
		</select>
<input type="text" name="email_value" id="email_value" value="<?php if(isset($_POST['email_value'])) {echo $_POST['email_value'];} else {echo 'Email Address';} ?>" onfocus="this.value='';" />

Open in new window

Second Form:
<select name="item_options[location_state]" id="bike_state" {sticky}>
						<option disabled >Choose State</option>
						<?php
							$query = ee()->db->query('SELECT state FROM exp_state_rates');
							foreach ($query->result() AS $row)
							{
								echo '<option name="bike_state" class="option-center" value="'.$row->state.'" >'.$row->state.'</option>';	
							}
						?>
					</select>		
<input type="text" name="item_options[contact_email]" value="" />	

Open in new window

Any ideas on how I need to write the "if(isset($_POST" statement?  Thanks for your help.  My initial ideas did not work and I feel like I am spinning my wheels.
0
rgranlund
Asked:
rgranlund
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
This is what I use.
if (!isset($_POST['fname'])) {$fname = "";} else {$fname = $_POST['fname'];}

Open in new window

0
 
rgranlundAuthor Commented:
What about the <select> <option> ???
0
 
Dave BaldwinFixer of ProblemsCommented:
What about it?  Use the result from the 'if' statement in the Select statement.  Separate lines.  Every PHP page that I post to has the 'if(!isset...' statements for all of the incoming variables at the top of the page.  I would never put all that PHP in the middle of that.  If you look at the PHP Email demo I have posted many times you will see that at the top of that file.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now