carlpj51 Posted October 20, 2008 Share Posted October 20, 2008 When a user makes an error in one of my self processing forms and the form is returned back to them for corrections, one of the fields won't remember the posted value. The form is written as a function and is called by the processing page. When I upload the script, the form field displays properly but on resubmit (with errors) it remains unselected. The part of the form I'm having a problem with is highlighted in red: ]<html> <!-- step222222222222222222222222222222222222222222222222222222 --> <p><sub><img src="/tt_image/step2.gif" alt="step 2" /> </sub>  Select Asset ID/Location: <?php // //GENERATE & EXECUTE QUERY $asloc_sql = "SELECT worklocation_id, worklocation_description FROM work_location_info ORDER BY worklocation_id DESC"; $asloc_result = mysql_query($asloc_sql) or die (mysql_error()); if (!$asloc_result) { echo "An Error occurred connecting to Database!"; } else { echo "<SELECT name=\"assetlocation[]\"> <OPTION value=\"\"> --- Select Asset ID/Location --- </OPTION>"; while ($row = mysql_fetch_array($asloc_result)) { $wl_id = $row["worklocation_id"]; $wl_des = $row["worklocation_description"]; if ($row == $_POST['assetlocation']) { echo "<OPTION value=\"$wl_id-$wl_des\" selected>$wl_id-$wl_desc</OPTION>"; } else { echo "<OPTION value=\"$wl_id-$wl_des\"> $wl_id-$wl_des</OPTION>"; } } echo "</SELECT>"; } ?> </p> </html> [/color] Thank you for helping!!! Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/ Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 $row is an array, so therefore it'll never be equal to your $_POST['assetlocation']...You probably want some value from $row. >_< Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670456 Share on other sites More sharing options...
carlpj51 Posted October 20, 2008 Author Share Posted October 20, 2008 I tried that. Instead of "while ($row = mysql_fetch_array($asloc_result))" , I wrote "while($wl_des = mysql_fetch_array($asloc_result))", also tried "while($wl_id = mysql_fetch_array($asloc_result))" to no avail. Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670463 Share on other sites More sharing options...
DarkWater Posted October 20, 2008 Share Posted October 20, 2008 Uhh...Do you know PHP, or is this someone else's script that you're modifying? If you look, that line has absolutely nothing to do with $_POST, so why would you touch it? Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670467 Share on other sites More sharing options...
carlpj51 Posted October 20, 2008 Author Share Posted October 20, 2008 I'm sorry. I meant that I've tried if($wl_des == $_POST['assetlocation']) also if($wl_id == $_POST['assetlocation']) with no luck. Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670472 Share on other sites More sharing options...
DarkWater Posted October 21, 2008 Share Posted October 21, 2008 Well, your script says that the 'value' of the select tag is "$wl_id - $wl_des", so try that. Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670490 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I just tried if ($wl_des-$wl_id == $_POST['assetlocation']) with and without quotes, with parenthesis just around the two variables, and I also tried reversing the order still with no luck. Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670499 Share on other sites More sharing options...
DarkWater Posted October 21, 2008 Share Posted October 21, 2008 Put double quotes " " around $wl_des-$wl_id. "$wl_des-$wl_id" Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670500 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I tried the following...none worked. if(("$wl_id-$wl_des") == $_POST['assetlocation']) if("$wl_id-$wl_des" == $_POST['assetlocation']) if(("$wl_des-$wl_id") == $_POST['assetlocation']) if("$wl_des-$wl_id" == $_POST['assetlocation']) Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670509 Share on other sites More sharing options...
DarkWater Posted October 21, 2008 Share Posted October 21, 2008 Add this line in there for me (before the if statement): echo "$wl_id-$wl_des | {$_POST['assetlocation']}"; EDIT: OH WAIT. You have it set as an array on the HTML. Remove the [] in the HTML. Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670510 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I took out the [] in the html as you suggested also placed the echo in as follows: echo "<SELECT name=\"assetlocation\"> <OPTION value=\"\"> --- Select Asset ID/Location --- </OPTION>"; while ($row = mysql_fetch_array($asloc_result)) { $wl_id = $row["worklocation_id"]; $wl_des = $row["worklocation_description"]; echo "$wl_id-$wl_des | {$_POST['assetlocation']}"; if (("$wl_des-$wl_id") == $_POST['assetlocation']) { echo "<OPTION value=\"$wl_id-$wl_des\" selected>$wl_id-$wl_desc</OPTION>"; } else { echo "<OPTION value=\"$wl_id-$wl_des\"> $wl_id-$wl_des</OPTION>"; } } ....and still no luck Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670514 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I didn't tell you what happened with the echo-- nothing. On the web page on the form resubmit there was not value posted on the echo command, neither the $wl_id-$wl_des nor the {$_POST['assetlocation']} Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670516 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I got field to partially work by taking out the [] in the SELECT statement, also made sure the variables $wl_id-$wl_des were in the correct order. So now on resubmit with errors, I get the drop down menu to show the location id but still no location description.....Still working on it. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670537 Share on other sites More sharing options...
carlpj51 Posted October 21, 2008 Author Share Posted October 21, 2008 I thank you DarkWater for all your help! I found another small error which was preventing the location description from printing on the error resubmit page. Thanks Again! if (("$wl_des-$wl_id") == $_POST['assetlocation']) { echo "<OPTION value=\"$wl_id-$wl_des\" selected>$wl_id-$wl_desc</OPTION>"; } else { echo "<OPTION value=\"$wl_id-$wl_des\"> $wl_id-$wl_des</OPTION>"; Link to comment https://forums.phpfreaks.com/topic/129325-solved-self-processing-form-field-wont-keep-its-value/#findComment-670541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.