Connexion | Inscription | FAQ

Storing the value of a drop box as a variable name

+ Publier une réponse

2 messages Page 1 sur 1

Storing the value of a drop box as a variable name

par adke001458 » Lun Août 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.

Avatar de l’utilisateur


  • Messages: 1
  • Inscrit le: Lun Août 11, 2014 9:05 am

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

par XainPro » Mer Sep 24, 2014 11:29 am

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

${'a' . 'b'} = 'hello there';
echo $ab; // hello there
Avatar de l’utilisateur


  • Messages: 3933
  • Inscrit le: Ven Fév 17, 2012 8:10 pm

+ Publier une réponse

Page 1 sur 1