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

    Angry Unanswered: $HTTP_POST_VAR form variables


    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....


    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.


    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
    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:

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

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

    Change your code from




    and it should all work.

  4. #4
    Join Date
    Jan 2004
    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.
    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