alanl1 Posted August 1, 2013 Share Posted August 1, 2013 Hi Professionals I am stuck here trying to retrieve some values and update the DB I have a dynamic drop down box that is created within my loop on the first page like so <select name="<?php echo "dropdown[" .$c ."]" ?>" id="<?php echo $data[$c] ?>" ><?php echo "<option value='y'>Keep Existing</option>"; echo "<option value='n'>Ignore</option>"; echo "<option value='tick'>Cleanse</option>"; ?></select> When I click view source I get <select name="dropdown[0]" id="SoftwareManufacturer" ><option value='y'>Keep Existing</option><option value='n'>Ignore</option><option value='tick'>Cleanse</option></select> I can pull the name out no problem, but what I am looking for is to retrieve the ID as that is my actual db column name so I would need to update that column in the DB. for instance if the dropdown name = y then update db set (ID of the dropdown to something) hope this makes sense foreach ($_POST['dropdown'] as $numcolumns=>$downboxValue) { if($downboxValue === 'y') /*This is set to KEEP EXISTING so we need to keep this spreadshet column */ { echo "this is a y" .$downboxvalue; } elseif($downboxValue === 'n') /*This is set to IGNORE so we need to drop this spreadshet column */ { echo "this is a n" .$downboxvalue; } else /*This is set to a TICK so we need to cleanse this db value */ { echo "this is a tick" .$downboxvalue; } } Quote Link to comment https://forums.phpfreaks.com/topic/280702-trying-to-retrieve-a-dropdown-value-and-id/ Share on other sites More sharing options...
Muddy_Funster Posted August 1, 2013 Share Posted August 1, 2013 in your code $numcolumns should contain your ID value Quote Link to comment https://forums.phpfreaks.com/topic/280702-trying-to-retrieve-a-dropdown-value-and-id/#findComment-1442916 Share on other sites More sharing options...
Solution lemmin Posted August 1, 2013 Solution Share Posted August 1, 2013 Why not use the id as the index of your dropdown array instead of the numeric value $c? <select name="<?php echo "dropdown[".$data[$c]."]" ?>" id="<?php echo $data[$c] ?>" ><?php Then you can loop through each drop down like so: foreach ($_POST['dropdown'] as $dbcolumn => $value) Something you should note, though: Accepting the name of a column from user input will leave your application open for SQL injection. Quote Link to comment https://forums.phpfreaks.com/topic/280702-trying-to-retrieve-a-dropdown-value-and-id/#findComment-1443027 Share on other sites More sharing options...
alanl1 Posted August 7, 2013 Author Share Posted August 7, 2013 thanks that works Quote Link to comment https://forums.phpfreaks.com/topic/280702-trying-to-retrieve-a-dropdown-value-and-id/#findComment-1443918 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.