Jump to content

trying to retrieve a dropdown value and id


alanl1

Recommended Posts

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;
 }
 
  
}
 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.