Announcement

Collapse
No announcement yet.

How to pass array from a Form to another applicaton?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass array from a Form to another applicaton?

    Hi,

    I have a form (blank) with a listbox and a submit button.

    code:
    $gnNoAry = array();
    sc_set_global($gnNoAry);

    echo "<form id='form1' name='form1' method='post' action='../showresult.php'>";
    echo " <select name='gnNoAry[]' size='30' multiple='multiple' tabindex='1' method='post'>";
    while ($row = mysql_fetch_array($result)) {
    $thename = $row['no']." ".$row['cname'];
    $theno = $row['no'];
    echo " <option value=$gnNoAry>$thename</option>";
    }
    echo " </select>";
    When the user select some item in the list and press "submit", I want to pass the selected items in an array gnNoAry to another application showresult.php

    showresult.php
    <?php
    echo 'gnNoAry:';
    print_r($_POST['gnNoAry']);
    ?>
    However, I got the follow error message:
    gnNoAry: Notice: Undefined variable: _post in C:\...\showresult.php

    Can some help me?

    Best regards,
    Lai

  • #2
    Hi Lai,
    Can you see the variable in the second app by doing following?
    echo [gnNoAry];

    Another trick I use when testing variables and such is to put the global in one of the title fields in the header fyi - avoids having to echo things...

    make sure in the first application, under the Application setting, you check that [gnNoAry] is going OUT as session. Then in second app make sure the same setting there is IN as session.

    I hope tat helps. I am have not passed arrays between apps, but seems like it should be the same as other variables.

    Note that I , as a personal rule, always set my main global variables up , even if NULL, in the login app. That way I know they exists when using them later. You can then just do things like [glo_my_var1] = "1234"; or read it by using [glo_my_var1].

    I always set my naming to have [glo_something1], [glo_something2], etc. Just to give them clean naming as universal globals. For passing between just 2 apps, I usually do something like [v_my_var1], and use that name on both sides. Note that when you make links between apps, something very useful to learn and do, I use that naming as well.

    Anyway, hope that works for you. Let us all know if arrays can be passed ok
    peace,
    Jamie

    Comment


    • #3
      Hi Jamie,

      I followed your suggestions and it worked. Excellent!

      Fixed codes:
      echo " <select name='gnNoAry[]' size='30' multiple='multiple' tabindex='1' method='post'>";
      while ($row = mysql_fetch_array($result)) {
      $thename = $row['no']." ".$row['cname'];
      $theno = $row['no'];
      echo " <option value=$thename>$thename</option>";
      }
      echo " </select>";
      Best of all, your coding advices on global and local variables are valuable to me.

      Thanks a lot.

      Best regards, Lai
      Last edited by laiyiulam; 07-04-2013, 09:27 AM.

      Comment


      • #4
        how to pass variable values from one application to another

        example program to pass values from one application to another application
        vijay

        Comment

        Working...
        X