Jump to content

populate a $_REQUEST variable value from database record - how?


Recommended Posts

I am trying to get the values posted from a form select. The select name is dynamic, meaning that the name value is defined by a database record.

 

In the form processing script, I want to call back that value via a $_REQUEST.

 

I cannot know in advance what the value of the $_request will be (eg, $var=$_REQUEST['foo']; ) but I do know that the value is one originitating from a database table. Knowing this I create a database call, then use a foreach to loop through the possible values.

 

I want to create a $_request for each pass.

 

eg..

$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`");
$prod_prop_name_array= array();
while($data9=mysql_fetch_array($prod_prop_name)) {$prod_prop_name_array[]=$data9;}
foreach($prod_prop_name_array as $rowNum => $data9){
    $option_id=$data9[0];
    $option_name=$data9[1];
    if($option_name==""){}
    else{$varnval=$_REQUEST[$option_name];  // this is my try at getting the var value
    echo "$varnval"; // this is the output test
    }
}

 

Problem I am having is that on the local server, I get a value, but on the webserver I get none. You can see I am using an echo to see what happens. $varnval

 

Can anyone suggest a workaround for this issue?

 

Many Thanks

 

KF

Well how about this, do you create the select dropdown menu or do you have access to that code? If you do, why not add a dbs_  before the name of the select, then you can easily access it using a foreach loop:

 

<?php
foreach ($_REQUEST as $key => $val) {
if (strstr($key, "dbs_")) {
	$value = $val;
	break;
}
}

echo "The key used was $key which contained $value for a value.";
?>

 

If you can do it that way, much easier and way more efficient :)

 

thanks for the reply..

 

this is my complete select build..

$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`");
   $prod_prop_name_array= array();
   while($data9=mysql_fetch_array($prod_prop_name)) {$prod_prop_name_array[]=$data9;}

   foreach($prod_prop_name_array as $rowNum => $data9) {
   $prod_prop_id=$data9[0]; $prod_prop_title=$data9[1];
   
   ////////////////////////////////////////////////////////////////////
   
      $prod_prop_attri=mysql_query("SELECT * FROM `dshop_options_values` WHERE `prod_id`='".$selected_product."' AND `attri_name`='".$prod_prop_title."' ORDER BY `attri_value` ASC ");
      $prod_prop_attri_array= array();
      while($data10=mysql_fetch_array($prod_prop_attri)) {$prod_prop_attri_array[]=$data10;}   
         if(!$prod_prop_attri_array){}
         else{
         ?>
         <div class='left'><?php echo $prod_prop_title?>
         <select name='<? echo $prod_prop_title?>'>
         <option value="select">Select</option>
         <?php   
         foreach($prod_prop_attri_array as $rowNum => $data10){
         $itemname=$data10[2]; $itemvalue=$data10[3]; $itemprice=$data10[4];
            if($itemprice<="0"){
            ?>
            <option value='<?php echo $itemvalue?>'><?php echo $itemvalue?></option>
                </select>
                <?php
            }
            else{
            ?>
            <option value='<?php echo $itemvalue?>'><?php echo $itemvalue." - ".$currency_type.$itemprice?></option>
            <?php
            }      
         }
         ?>
            </select></br></br></div>
            <?php
         }

}

 

Any help appreciated, i have to produce a viable working demo for the client in the morning, and already 01:44GMT here.

 

Although i am tackling a very complex system (in total), by experience of array use is still building.

 

KF

Was my instructions/logic not clear?

 

 <select name='dbs_<? echo $prod_prop_title?>'>[code]

Is the only change you would need to do, adding that prefix will allow you to know which item in the request array you want to access on the next page. Then you would use the code I posted above to pull it out on the next page.

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.