How to pass this dropdown to another PHP page

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 13
Joined: Thu Sep 27, 2012 10:55 am

Tue Oct 02, 2012 5:28 pm

I think you would want something like the following. Also, in your table customer, you should have a customer id. The option value would be the customers id and the string to select would be the customer name.

Code: Select all

 /* up here is the query. Should use prepared statements instead of mysql_* functions.*/
// query returns a resource with the user name and id that is then assigned to an array named $actives
// using mysqli and object oriented style here
while ($row = $result->fetch_assoc()) {
 $actives[] = $row;
// duck out of PHP and continue with HTML form
   //back in to PHP
   if (isset($actives)){
     echo "<select name=\"users\">";
     foreach ($actives as $value){  
       printf('<option value = %s > %s </option>',$value['customerID'],$value['customerName']);
     echo "</select>";
This will produce one menu with each of your user names as menu options. Then you could either assign the selection to a session variable or pass it to another script as a $_POST['users'] super global array. Say the user selects John Doe with an id of 21. $_POST['users'] would have the value 21.
Good Luck

Post Reply