POST arrays - each as SQL statement

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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  

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
    var_dump ($value);

Results in:

array(5) {
  string(1) "1"
  string(1) "2"
  string(3) "N/A"
  string(1) "0"
  string(12) "sdfsdfsdfsdf"

So, now I know that $value has 5 keys:

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

Karl Groves

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:


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!

<!-- Example start //-->

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

<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>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><input type='submit' /></p>

<!-- Example end //-->

Karl Groves wrote: (heavily snipped)
Quoted text here. Click to load it

Re: POST arrays - each as SQL statement

Quoted text here. Click to load it

Worked perfectly! Thanks!

Karl Groves

Site Timeline