form with dynamic questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toffee

    form with dynamic questions

    Hi all,

    I've a mysql table where i stored a list of questions. My php script
    executes a query which yields a different number of questions every time; i
    used the loop function to create an input field for each question in the
    form; and dynamically referencing each input name with the question number
    i.e. question 1 is called q1, question 2 named q2, and so on.
    The data is submitted using POST. I then try to retrieve all the answers by
    doing a loop and using something like echo '$_POST['q'.$n.'']'; except the
    syntax doesnt seem to work.
    Can anyone please tell me what am doing wrong - or a better way of doing
    this.

    Many thanks

    T


  • Jerry Stuckle

    #2
    Re: form with dynamic questions

    toffee wrote:
    Hi all,
    >
    I've a mysql table where i stored a list of questions. My php script
    executes a query which yields a different number of questions every time; i
    used the loop function to create an input field for each question in the
    form; and dynamically referencing each input name with the question number
    i.e. question 1 is called q1, question 2 named q2, and so on.
    The data is submitted using POST. I then try to retrieve all the answers by
    doing a loop and using something like echo '$_POST['q'.$n.'']'; except the
    syntax doesnt seem to work.
    Can anyone please tell me what am doing wrong - or a better way of doing
    this.
    >
    Many thanks
    >
    T
    >
    >
    Why not use an array? Then you can use $_POST["q[$n]"];

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Pedro Graca

      #3
      Re: form with dynamic questions

      ["Followup-To:" header set to comp.lang.php.]
      toffee wrote:
      the syntax doesnt seem to work.
      echo '$_POST['q'.$n.'']';
      echo $_POST['q' . $n];


      or

      $index = 'q' . $n;
      echo $_POST[$index];

      --
      File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

      Comment

      Working...