POST arrays - each as SQL statement

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

    POST arrays - each as SQL statement

    I have a rather long form (122 SETS of questions - don't worry, it is
    just me using it, lol)

    I have the questions set up as "Survey ID, Question ID, Answer, Impact,
    Comments", which I have set up so that each question is an array, like
    so:
    ques_1['survey_id']
    ques_1['question_id']
    ques_1['answer']
    ques_1['impact']
    ques_1['comments']

    I want to dynamically create SQL statements for each of these arrays,
    looping through the POST array, creating & running each of these
    dynamically created SQL statements.

    Unfortunately, when I attempt to access each array, I can't get the
    values of each key.

    For instance, consider the following:

    foreach ( $HTTP_POST_VARS as $key => $value ) {
    // I know for a fact, $value will be an array
    print("<pre>");
    var_dump ($value);
    print("</pre>");
    }

    Results in:

    array(5) {
    ["\'question_id\ '"]=>
    string(1) "1"
    ["\'survey_i d\'"]=>
    string(1) "2"
    ["\'answer\' "]=>
    string(3) "N/A"
    ["\'impact\' "]=>
    string(1) "0"
    ["\'comments \'"]=>
    string(12) "sdfsdfsdfs df"
    }


    So, now I know that $value has 5 keys:
    question_id
    survey_id
    answer
    impact
    comments


    So, why can't I access $value['question_id']; (or any of the other
    values of the other keys)?




    --
    Karl Groves

  • HC

    #2
    Re: POST arrays - each as SQL statement

    Hi Karl!

    I think your issue lies in the naming of your HTML form elements. I
    would name them like such:

    ques_1[survey_id]

    Note that there are no quotes around survey_id. Here is a quick example
    of what I think you may be after. If I don't quite have it, feel free
    to post back and I'll see what I can do.

    Have fun!
    HC



    <!-- Example start //-->

    <?PHP
    // I prefer using $_POST instead of $HTTP_POST_VARS .
    if ($_POST) {
    echo "<pre>";
    print_r($_POST) ;
    echo "</pre>";
    }
    ?>

    <html><body>
    <form method="post" action="">
    <p>Question 1:<br />
    <input type="text" name="ques_1[survey_id]" />
    <input type="text" name="ques_1[question_id]" />
    <input type="text" name="ques_1[answer]" />
    <input type="text" name="ques_1[impact]" />
    <input type="text" name="ques_1[comments]" />
    </p>
    <p>Question 2:<br />
    <input type="text" name="ques_2[survey_id]" />
    <input type="text" name="ques_2[question_id]" />
    <input type="text" name="ques_2[answer]" />
    <input type="text" name="ques_2[impact]" />
    <input type="text" name="ques_2[comments]" />
    </p>
    <p><input type='submit' /></p>
    </form>
    </body></html>

    <!-- Example end //-->


    Karl Groves wrote: (heavily snipped)[color=blue]
    >
    > ques_1['question_id']
    >
    > So, why can't I access $value['question_id']; (or any of the other
    > values of the other keys)?
    >[/color]

    Comment

    • Karl Groves

      #3
      Re: POST arrays - each as SQL statement

      HC <e01@removethis .toao.net> wrote in news:tlkjg.1055 3$iF6.8007@pd7t w2no:
      [color=blue]
      > Hi Karl!
      >
      > I think your issue lies in the naming of your HTML form elements. I
      > would name them like such:
      >
      > ques_1[survey_id]
      >
      > Note that there are no quotes around survey_id. Here is a quick example
      > of what I think you may be after.[/color]
      <snip>

      Worked perfectly! Thanks!


      --
      Karl Groves

      Comment

      Working...