Login | Register | FAQ

Storing the value of a drop box as a variable name

+ Post a reply

2 posts Page 1 of 1

Storing the value of a drop box as a variable name

by adke001458 » Mon Aug 11, 2014 9:08 am

Hi All,

I'm a newbie to coding and php and have been trying to solve this problem for hours, so if someone could help me it would be greatly appreciated.

To simplify the situation, essentially I have a drop down box on a web page. This drop down box automatically fills with values that are the result of a query (on an oracle DB).

What I am trying to do is save the value of the dropbox at any moment into a variable. I want the variable name to be the actual value.

For example, lets say the dropbox contains A, B, C, D. If A is selected, I want the variable to be named A.

Here is the code that I have.

$conn = oci_connect(....);

if ($conn {

$query = "Select.......";
$stid = oci_parse($conn, $query);
$success = oci_execute($stid);


<form name="searchform" method="post" onsubmit="return check_my_form()">
<table align="center" bgcolor="#666666" border="0" cellpadding=0 width="100%">
<tr><td align="left">
<table align="left" bgcolor="#666666" cellpadding=2 border="0" STYLE="font-family:Arial;font-size : 0.8em">
<tr><td><font Color=white>Select Task : </font></td>
<td><select name="taskKey" STYLE="font-family:Arial;font-size : 0.8em" onChange="this.form.submit();">

while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_BOTH))
echo "<option value= '".$row[0]."'>" .$row[0]. "</option>";

} //end conn
$myTaskKey = $_POST["taskKey"];
echo $_POST["taskKey"];

the echo is showing as blank.

Please help.

User avatar


  • Posts: 1
  • Joined: Mon Aug 11, 2014 9:05 am

Re: Storing the value of a drop box as a variable name

by XainPro » Wed Sep 24, 2014 11:29 am

Using ${} is a way to create dynamic variables, simple example:

${'a' . 'b'} = 'hello there';
echo $ab; // hello there
User avatar


  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm

+ Post a reply

Page 1 of 1