I have tried this a few different ways including as a hidden value. I have 2 separate values I need assigned to $_SESSION variables, id and cust_name. Assigning them to the session in the foreach loop does not work because it breaks the echo output. The only way I found to get both values to the next url was by concatenating them to a delimiter but that appears to be causing me issues. Is there another/better way to assign .$item['id'].":".$item['cust_name']. to individual session variable 'or' separate element in a $_POST value= ?

     foreach ($result as $item){
                echo '<option value='.$item['id'].":".$item['cust_name'].'>';
                //echo '<option type="hidden" value='.$item['cust_name'].'>';
                echo ($item['cust_name'] .",". $item['cust_addr'] .",". $item['cust_phone'].","
. $item['id']."<br />\n");
                echo '</option>';
Was it helpful?

Solution 2

The only way you can push 2 variables to a second URL is by using javascript to populate a hidden variable on post, pulling information from a "data" attribute.

For example, you'd define the following as your option...

<option data-customerid="123" name="customername" value="Marty McFly">Marty McFly, 123 Fake Street, 555-555-5555</option>

Then, using javascript...

$("#myform").submit( function(eventObj){
  $(this).append('<input type="hidden" name="customerid" value="'+$('#myselect').find(':selected').attr('data-customerid');+'" /> ');               
  return true;

return true at the end, then allows for the form to be posted in your normal way.

You will need to change #myform and #myselect in the above to the ID of your form, and the ID of your select element respectively. If you want to send any more additional fields, repeat the line starting with `$(this), changing the ID accordingly.


Try closing your value tag like this, otherwise if cust_name contains space, it will be missed

echo '<option value="'.$item['id'].":".$item['cust_name'].'">';
              //    ^                                      ^ Add double quotes here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow