jim.davidson Posted May 9, 2007 Share Posted May 9, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/50716-help-needed-with-list-menu/ Share on other sites More sharing options...
Daniel0 Posted May 9, 2007 Share Posted May 9, 2007 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>"; // ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/50716-help-needed-with-list-menu/#findComment-249354 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.