Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how do I pass a username form variable from a drop down list/menu to another page?

Guest
Oct 20, 2009 Oct 20, 2009

Hi,

I have a login_success.php page that has a drop down list/menu (which lists usernames). I want the user to click on their user name, and when they click the submit button the username information to be passed over to the username.php page which will contain a recordset, sorted by username.

How do I pass the username info from the drop down list/menu to the username.php page?

The drop down menu is connected to a recordset listUsername, I have filtered the recordset with the Form Variable = username, and I have used the POST method to send the username to the page username.php. I'm not sure how to structure the php or which page to place it on.

<form id="form1" name="form1 method="post" action="username.php">

     <label for="username_id">choose username:</label>

     <select name="username_id" id-"username_id">

          <option value="1">username1</option>

          <option value="2">username2</option>

          <option value="3">username3</option>

          <option value="4">username4</option>

     </select>

     <input type="submit" name="send" id="send" value="Submit" />

     <input type="username" type="hidden" id="username" value="<?php echo $row_listUsername['username']; ?>" />

</form>

Could somebody help me please?

Thanks.

TOPICS
Server side applications
660
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 20, 2009 Oct 20, 2009

I would not post the variable over, In this case I personally would send it through the URL and use the $_GET method to retreve it. For Example.

<html>      <head>           <title>Test Page</title>           <script type="text/javascript">                function userID(){                     //var ID = form1.userIDs.selectedIndex;                     var user = form1.userIDs.options[form1.userIDs.selectedIndex].value;                     window.location = "test.html?userID=" + user;                }           </script>      </head>      <body>           <form id="form1">                <select name="userIDs" id="userIDs" onchange="userID();">                     <option>Select a User</option>                     <option value="1">User 1</option>                     <option value="2">User 2</option>                     <option value="3">User 3</option>                     <option value="4">User 4</option>                </select>           </form>      </body> </html>

//PAGE TO RETRIEVE THE USERNAME

<?php

if(isset($_GET['userID'])

{

     $userID = $_GET['userID'];

     echo $userID;

     die;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 21, 2009 Oct 21, 2009

Hi Cody.Rob,

thanks for getting back to me, I'm really new to PHP and I don't know anything about JavaScript.

I noticed in your sample code that the method and action aswell as the submit button had been left out. If I use the Get method to retrieve the code on my second page how do i send it from the first page?

Do I add the userIDs record primary key to a query string and pass it through a link instead of a submit button?

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 21, 2009 Oct 21, 2009
LATEST

You could, perhaps, store the value in a session?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines