Jump to content

trying to retrieve a dropdown value and id


alanl1
Go to solution Solved by lemmin,

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;
 }
 
  
}
 
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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