By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

POST arrays - each as SQL statement

P: n/a
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_id\'"]=>
string(1) "2"
["\'answer\'"]=>
string(3) "N/A"
["\'impact\'"]=>
string(1) "0"
["\'comments\'"]=>
string(12) "sdfsdfsdfsdf"
}
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
www.karlcore.com
Jun 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
HC
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)

ques_1['question_id']

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

Jun 12 '06 #2

P: n/a
HC <e0*@removethis.toao.net> wrote in news:tlkjg.10553$iF6.8007@pd7tw2no:
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.

<snip>

Worked perfectly! Thanks!
--
Karl Groves
www.karlcore.com
Jun 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.