Professional Web Applications Themes

Help with $_POST variables. Reading their names. - PHP Development

I have a dynamic form that that creates input variables named different things based on what it reads from the database. So, for example, it may create three fields, named ex12, ex23, and ex45 respectively, and send those fields and their values via POST to a PHP page. So these would be sent basically: $_POST['ex12'] which may equal "cow". $_POST['ex23'] which may equal "cat". $_POST['ex45'] which may equal "dog". Now, I can easily count how many variables are sent using count($_POST) and know that 3 variables were sent. The question is, how to I determine what the names of the ...

  1. #1

    Default Help with $_POST variables. Reading their names.

    I have a dynamic form that that creates input variables named different
    things based on what it reads from the database.

    So, for example, it may create three fields, named ex12, ex23, and ex45
    respectively, and send those fields and their values via POST to a PHP
    page.

    So these would be sent basically:
    $_POST['ex12'] which may equal "cow".
    $_POST['ex23'] which may equal "cat".
    $_POST['ex45'] which may equal "dog".

    Now, I can easily count how many variables are sent using count($_POST)
    and know that 3 variables were sent. The question is, how to I
    determine what the names of the variables are? How do I determine if
    sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?


    --
    [ Sugapablo ]
    [ [url]http://www.sugapablo.com[/url] <--music ]
    [ [url]http://www.sugapablo.net[/url] <--personal ]
    [ [email]sugapablo12jabber.com[/email] <--jabber IM ]
    Sugapablo Guest

  2. #2

    Default Re: Help with $_POST variables. Reading their names.

    Sugapablo <russREMOVEsugapablo.com> wrote:
    > I have a dynamic form that that creates input variables named
    > different things based on what it reads from the database.
    >
    > So, for example, it may create three fields, named ex12, ex23, and
    > ex45 respectively, and send those fields and their values via POST to
    > a PHP page.
    >
    > So these would be sent basically:
    > $_POST['ex12'] which may equal "cow".
    > $_POST['ex23'] which may equal "cat".
    > $_POST['ex45'] which may equal "dog".
    >
    > Now, I can easily count how many variables are sent using
    > count($_POST) and know that 3 variables were sent. The question is,
    > how to I determine what the names of the variables are? How do I
    > determine if sent were ex12, ex23, and ex45 as opposed to ex4, ex25,
    > and ex65?
    foreach($_POST as $key => $value){
    echo $key.": ".$value;
    }

    HTH;
    JOn
    Jon Kraft Guest

  3. #3

    Default Re: Help with $_POST variables. Reading their names.

    Sugapablo wrote:
    > I have a dynamic form that that creates input variables named different
    > things based on what it reads from the database.
    >
    > So, for example, it may create three fields, named ex12, ex23, and ex45
    > respectively, and send those fields and their values via POST to a PHP
    > page.
    >
    > So these would be sent basically:
    > $_POST['ex12'] which may equal "cow".
    > $_POST['ex23'] which may equal "cat".
    > $_POST['ex45'] which may equal "dog".
    >
    > Now, I can easily count how many variables are sent using count($_POST)
    > and know that 3 variables were sent. The question is, how to I
    > determine what the names of the variables are? How do I determine if
    > sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?
    First thing that comes to mind is:

    <?php
    foreach ($_POST as $k=>$v) {
    // $k is 'ex12', 'ex23', ...
    // $v is 'cow', 'dog', ...
    }
    ?>

    HTH
    --
    --= my mail address only accepts =--
    --= Content-Type: text/plain =--
    Pedro Graca Guest

  4. #4

    Default Re: Help with $_POST variables. Reading their names.

    Sugapablo, doing a poor impression of Quincy, said:
    >
    > determine what the names of the variables are? How do I determine if
    > sent were ex12, ex23, and ex45 as opposed to ex4, ex25, and ex65?
    one way would be to use a foreach loop:

    foreach($_POST as $key => $value)
    echo "variable $key had value $value\n";

    /joe
    --
    E. Robert Frank asks for help from Bwooce and Uncle Heinie Way. Jess does
    an impression of Kurt Eiselt for a router? The Knights of Parking cleverly
    punches Matt Labbe's desktop from Uni.
    Christian Debt Man Guest

  5. #5

    Default Re: Help with $_POST variables. Reading their names.

    In article <Xns943FB35A7FAD7jonjonuxcouk130.133.1.4>, Jon Kraft wrote:
    >
    > foreach($_POST as $key => $value){
    > echo $key.": ".$value;
    > }
    Thank you (to each who answered). :)

    --
    [ Sugapablo ]
    [ [url]http://www.sugapablo.com[/url] <--music ]
    [ [url]http://www.sugapablo.net[/url] <--personal ]
    [ [email]sugapablo12jabber.com[/email] <--jabber IM ]
    Sugapablo Guest

Similar Threads

  1. Accepting variables via $_GET and $_POST in same script ?
    By Zurab Davitiani in forum PHP Development
    Replies: 0
    Last Post: July 21st, 08:15 PM
  2. getting $_POST variables from form in a function
    By Jenkins in forum PHP Development
    Replies: 1
    Last Post: October 27th, 05:38 AM
  3. [PHP] dump $_POST into variables????
    By Joe Harman in forum PHP Development
    Replies: 1
    Last Post: July 13th, 02:58 PM
  4. Replies: 1
    Last Post: July 11th, 09:49 PM
  5. dump $_POST into variables????
    By Joe Harman in forum PHP Development
    Replies: 0
    Last Post: July 11th, 05:01 AM

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