Jump to content

Recommended Posts

I'm using Dreamweaver 8, mySQL 4.1.21, and PHP

 

Here's my problem

 

I have an update customer info form

 

The user enters the info, I check for errors if there are any I return user to the form to fix errors.

 

I got everything working except one part.

 

There is a list menu(populated from a recordset) to select the customers state. If the user makes an error somewhere along the line, when I return them to the update form the state they selected is gone and the user is forced to select again.

 

How do I get that state to appear when returned to form?

 

Heres the code for the list menu:

 

<select name="contact_state" class="text_background" id="contact_state" title="<?php echo $row_findStateName['state_name']; ?>">

        <option value=""><?php echo $row_findStateName['state_name']; ?></option>

        <?php  // code for states menu

  do { 

  ?>

        <option value="<?php echo $row_GetStates['abbreviation']?>"><?php echo $row_GetStates['state_name']?></option>

        <?php

    } while ($row_GetStates = mysql_fetch_assoc($GetStates));

      $rows = mysql_num_rows($GetStates);

      if($rows > 0) {

        mysql_data_seek($GetStates, 0);

  $row_GetStates = mysql_fetch_assoc($GetStates);

    }

?>

      </select>

 

Link to comment
https://forums.phpfreaks.com/topic/50716-help-needed-with-list-menu/
Share on other sites

Instead of sending them back, render the form again. You are then able to choose which choose which one that is selected.

 

Example (change to fit your code):

 

<?php
// ...
// $_GET['animal'] holds the selected value
$select = array(
	'tiger' => 'Tiger',
	'elephant' => 'Elephant',
	'dog' => 'Dog',
	//...
);

echo "<label for='animal_select'>Please select your favorite animal</label>:\n<select name='animal' id='animal_select'>";
foreach($select as $value => $text)
{
$selected = $_GET['animal']==$value ? " selected='selected'" : null;
echo "\t<option value='{$value}'{$selected}>{$text}</option>\n";
}
echo "</select>";
// ...
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.