views:

59

answers:

2

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];
echo"$option_name";
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

A: 

Is it possible that the PHP version on your server is older than 4.1? That is when the $_REQUEST variable was introduced.

You can do a <?php echo(phpinfo()); ?> to check the PHP version on the server.

jaywon
No, server is in fact newer (version).i have tried this with both `_post` and `_get` with the same results.I am using the super global to ease tests.
KelsoField
hmmm...not sure why that is happening, but you could loop through the <b> array_keys()</b> array and find a match, and then get the value that way by index?
jaywon
Thanks for the suggestion, although I am creating a very complex app, my understanding of all uses of arrays and methods is still fairly basic.Could you please provide an example of this, or point towards a resource?This HAS to be working by the morning (01:27 GMT here) so panic mode kicking in :)
KelsoField
as a footnote, I know the data is in the array, as I am calling it directly via the db. Creating a variable from each result found (db) in order to check against is my main issue.
KelsoField
Just noticed this...in the url the data is like this.. `index.php?Print+Type=Canvas+Print`I am asking the script to check the value against the database value so there is an errorthe namein the post is being sent as `Print+Type` and the value as `Canvas+Print` yet the db record of course has psaces not a `+`.Do you think this could be the issue?I will try a `str_replace` but I am not confident..
KelsoField
yea, i would think that that IS the issue. Obviously the strings don't match in that case. you could try urlencode($option_name) on your database value to put the + sign in the database value for comparison, or a string replace as you suggested would probably do the trick as well.
jaywon
A: 

Try the following to test you cases:

$result = mysql_query("SELECT * FROM `dshop_options_name`") or die("Something went wrong trying to retrieve the names of the options: ".mysql_error());

$options = array();

while ($each = mysql_fetch_array($result))
    $options[] = $each;

mysql_free_result($result);

echo "Name of options: ".join(", ",$options)."<br><br>\n";

foreach ($options as $option)
{
    if (isset($_REQUEST[$option]))
        echo "\$_REQUEST[\$option]: ".$_REQUEST[$option]."<br>\n";
    elseif (isset($_GET[$option]))
        echo "\$_GET[\$option]: ".$_GET[$option]."<br>\n";
    elseif (isset($_POST[$option]))
        echo "\$_POST[\$option]: ".$_POST[$option]."<br>\n";
}

echo "<pre>_REQUEST vars:<br>\n".print_r($_REQUEST,true)."</pre>\n";
echo "<pre>_GET vars:<br>\n".print_r($_GET,true)."</pre>\n";
echo "<pre>_POST vars:<br>\n".print_r($_POST,true)."</pre>\n";
Ast Derek