Professional Web Applications Themes

passing variables to subsequent pages - PHP Development

I have a two page search. The first page queries a database and creates a list of MANUFACTURERS from which the visitor can select all, one or multiple entries. The page is submitted via GET to the second page of the search. The second page uses the array of selected MANUFACTURERS to create a selectable list of MODELS from which the visitor can select all, one or multiple entries. This page is then submitted to the results page via GET. The problem is that to correctly query the database for results, I need to get the array of selected MANUFACTURERS ...

  1. #1

    Default passing variables to subsequent pages

    I have a two page search. The first page queries a database and creates a
    list of MANUFACTURERS from which the visitor can select all, one or
    multiple entries. The page is submitted via GET to the second page of the
    search. The second page uses the array of selected MANUFACTURERS to create
    a selectable list of MODELS from which the visitor can select all, one or
    multiple entries. This page is then submitted to the results page via GET.

    The problem is that to correctly query the database for results, I need to get the array of selected MANUFACTURERS to
    the results page. I'm using a SUBMIT button and don't know how to include
    this information in the URL being passed. Any
    suggestions?

    Thanx,
    --
    Robb Kerr
    Digital IGUANA
    Helping Digital Artists Achieve their Dreams
    http://www.digitaliguana.com
    http://www.cancerreallys.org
    Robb Guest

  2. #2

    Default Re: [PHP] passing variables to subsequent pages


    On Monday, November 3, 2003, at 12:44 AM, Robb Kerr wrote:
     

    If you're using a submit button, then you can have a hidden form field:
    <form ...>
    <input type='hidden' name='manufacturer'
    value='<?=$_GET['manufacturer']?>' />
    <input type='submit' ...>
    </form>

    of just add it to the URL of the form action:

    <form action='nextpage.php' method='get'>
    ....
    </form>

    becomes:

    <form action='nextpage.php?manifacturer=<?=$_GET['manufacturer']?>'
    method='get'>
    ....
    </form>

    Make sense?

    You could also consider sessions, cookies, etc etc.


    Justin French
    Justin Guest

  3. #3

    Default Re: [PHP] passing variables to subsequent pages

    On Sun, 2 Nov 2003 07:44:29 -0600, you wrote:
     

    Flip to POST instead of GET, for the sake of neatness.

    The key to passing multiple values is the "[]" at the end of the checkbox
    name in the form:

    <?
    if (isset ($fruit))
    {
    print_r ($fruit);
    }
    ?>
    <form method="post" action="<? echo($PHP_SELF); ?>">
    <p><input type="checkbox" name="fruit[]" value="apple"> Apple</p>
    <p><input type="checkbox" name="fruit[]" value="orange"> Orange</p>
    <p><input type="checkbox" name="fruit[]" value="pear"> Pear</p>
    <p><input type="checkbox" name="fruit[]" value="banana"> Banana</p>
    <p><input type="checkbox" name="fruit[]" value="tangerine">
    Tangerine</p>
    <p><input type="submit" name="Go" value="Go"></p>
    </form>
    David Guest

  4. #4

    Default Re: passing variables to subsequent pages

    Both suggestions were very helpful. But, I've still got a problem. The
    $MANUFACTURERS variable contains an array. I'm trying to pass this array
    with either the GET or POST method. I've tried the following to no avail...

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value=<?php $manufacturer ?>>

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value=<?php echo $manufacturer ?>>

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value="<?php $manufacturer ?>">

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value='<?=$_GET['manufacturer']?>'> //as per Justin's suggestion

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value="$manufacturer">

    <input name="manufacturer[]" type="hidden" multiple id="manufacturer[]"
    value=$manufacturer>


    Except for the last two entries, the others all passed
    "...&manufacturer%5B%5D=Array..."

    Any more suggestions?

    Thanx,
    --
    Robb Kerr
    Digital IGUANA
    Robb Guest

  5. #5

    Default Re: [PHP] passing variables to subsequent pages

    --- Justin French <com.au> wrote: 

    Unless I'm mistaken (which is possible), this won't work. When the
    form method is GET, the query string is constructed using the form
    fields. Therefore, the manufacturer will be lost.

    Hope that helps.

    Chris

    =====
    My Blog
    http://shiflett.org/
    HTTP Developer's Handbook
    http://httphandbook.org/
    RAMP Training Courses
    http://www.nyphp.org/ramp
    Chris Guest

Similar Threads

  1. Passing Variables
    By LegeDoos in forum Macromedia Flash Data Integration
    Replies: 16
    Last Post: July 1st, 08:25 PM
  2. Passing ASP Variables
    By Darren Woodbrey in forum ASP Database
    Replies: 2
    Last Post: April 19th, 04:49 AM
  3. Replies: 3
    Last Post: November 14th, 08:16 PM
  4. passing variables between pages
    By Matthew in forum PHP Development
    Replies: 11
    Last Post: October 14th, 04:29 PM
  5. [PHP] Passing variables between pages
    By Jay in forum PHP Development
    Replies: 2
    Last Post: October 14th, 04:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139