upload.php

<form name="selectionForm" method="POST" action='query.php'>

echo "<select name='$q2['type']'>";
       //echo "<select name='selecttype'>";
       echo "<option value='Regular Project'>Regular Project</option>";
       echo "<option value='FSA Project'>FSA Project</option>";
       echo "</select></td>";
       echo "<input type='hidden' name='mid' value='$q2[0]'>";
       echo "<td width='140'><textarea rows='2' name='comments[]' cols='20' ></textarea></td>\n";
       echo "</tr>\n";

</form>

query.php

$selecttype = $_POST['selecttype'];

instead of calling 'selecttype' i want to call '$q2['type']'. how to get this value as dynamic.

Member Avatar for diafol

The hidden field should work:

echo "<input type='hidden' name='selectname' value='{$q2['type']}'>";

Retrieve by:

$_POST[$_POST['selectname']]

That should be equivalent to $_POST[$q2['type']]

However, that's pretty messy. You could search for POST keys with known values, but thinking about it, that may be even messier.

Thanks, hidden field should work, but inbetween like this.. i tried and outside of select tag the values are displaying..

echo "<select name='selecttype'>";

       echo "<input type='hidden' name='selecttype' value='{$q2[0]}'>";

       echo "<option value='Regular Project' >Regular Project</option>";
       echo "<option value='FSA Project'>FSA Project</option>";
       echo "<option value='TGF Project'>TGF Project</option>";
       echo "</select></td>";
Member Avatar for diafol

Sorry don't understand. What's that got to do with the solution I proposed? You wanted to know how to pass a dynamic value for the select field and I showed you how it could be done. Now you've gone and changed the code from the commented out example in the original post to your last post.

I believe the solution was successful in giving $q2['type']? Please clarify what you mean. Did I waste my time proposing a solution to your original question? Did I misunderstand?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.