Jump to content

Selecting a Value from a dynamically generated drop down box


surajkandukuri

Recommended Posts

Hi All,

 

      I am new to php scripting and write now i am stuck with my coding. I have drop down box which gets its values from mysql database, I can see correct values in the drop down box, but the problem is I AM unable to store the value selected by the user in a variable. The code is attached below.

 

        $strQuery = "select * from employees";

             

  $rsrcResult = mysql_query($strQuery);

 

  while($arrayRow = mysql_fetch_assoc($rsrcResult)) {

      $strA = $arrayRow["employee_id"];

      $strB = $arrayRow["employeename"];

      echo "<option selected='selected' value=\"$selectedvalue\">$strB</option>\n";

  }

Any help is really appreciated.

 

Link to comment
Share on other sites

So you wish to store the selected value in a variable? In order to do that the form would need to be submitted (PHP is server side, so it can only see the selected value once you submit the information back to the server). You would then use either the $_POST or $_GET superglobal arrays to fetch the value based on the name attribute of the select node.

Link to comment
Share on other sites

Thank you Cags!!

 

              I tried submitting the Drop down box using POST method but once the page refreshes , Drop down box becomes empty with no values in it, and also I cannot ECHO the value selected using echo($selectedvalue). I have changed the value attribute of the above code to NAME attribute

Link to comment
Share on other sites

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.