Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    2

    Angry Unanswered: $HTTP_POST_VAR form variables

    Hi,

    New to the forum and was just wondering if some one could tell me why I can not use a variable inside the $HTTP_POST_VAR. For example....

    $HTTP_POST_VAR['$variable'];

    it is just that I have witten some script to dynamically create a form depending on what options are selected while you are filling it out how ever when ever I submit the form I need to query the data base first to determine how many form variables would have been created while the form was been put together.

    Example

    echo "<input type=\"checkbox\" name=\"$variable\" value=\"secondvar\"> ";

    this is is the sort of input I am using in the form however the problem lies once you have submitted the form is to work out how access the variable that was just submitted. In the case above I would normally have a fixed name for the form check box and so access it by $HTTP_POST_VAR['checkbox'] howeverI need to make the name variable. I am really stuck any help would be really apciated

  2. #2
    Join Date
    Jan 2004
    Posts
    6
    An HTML POST'ed checkbox variable unsets itself if it is not checked. If you have code that checks to see if you have been to that form before (e.g. a form that refers to itself) and resets the checkbox based on that criteria, then you may need to use isset() on a different variable (one that is not a checkbox). If you only have checkboxes on the form you can check for the submit button variable. (I take this from php/manual/user notes)

    You should test the fallowing code:

    PHP Code:

    <?php
    if (isset ($HTTP_POST_VARS['submit'])) {
    echo 
    'value of <b>var</b> is:' .  $HTTP_POST_VARS['var'] . '<br>and the value of <b>submit</b> is: ' $HTTP_POST_VARS['submit'];
    exit;
    }
    ?>
    <form action="<?php echo $PHP_SELF?>" method="post">
    <input name="var" type="checkbox" value="check" checked />
    <input name="submit" type="submit" value="submit" />
    </form>
    if the field is checked value of $HTTP_POST_VARS['var'] is ckeck.

  3. #3
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    There are 2 errors in your code: remove the quotes and the missing S ($HTTP_POST_VAR{S})

    Change your code from

    $HTTP_POST_VAR['$variable'];

    to

    $HTTP_POST_VARS[$variable];

    and it should all work.

  4. #4
    Join Date
    Jan 2004
    Posts
    2
    Thanks for that :-)

    I was able to get the code working with the help from Bill in another forum. I have posted my trial code that I finally got working just incase there if some one else had the same problem.

    Thanks again anyway for your reply and yes your right missed the S at the end of $HTTP_POST_VARS and of corse the quotes.

    http://forums.devshed.com/showthread...1&goto=newpost
    Last edited by davonz; 01-06-04 at 16:13.

Posting Permissions

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