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!!! Quote Link to comment 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. >_< Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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" Quote Link to comment 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']) Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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']} Quote Link to comment 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! Quote Link to comment 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>"; Quote Link to comment 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.