473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_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
2 1448
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dariusz | last post by:
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are...
5
by: Thejo | last post by:
Hi all, I started programming in PHP recently and have a query about empty $_POST arrays. I can see two scenarios when this could happen. 1. When some tries to directly load the page to which...
2
by: JJ Feminella | last post by:
This statement is legal C#: public const string day = "Sunday"; but this statement is not: public const string days = new string { "Sun", "Mon", "Tue" }; The C# Programmer's Reference...
33
by: Peter Seaman | last post by:
I understand that structures are value types and arrays and classes are reference types. But what about arrays as members of structures i.e. as in C struct x { int n; int a; }
9
by: David Helgason | last post by:
I'm calling one stored procedure with a prepared statement on the server with 6 arrays of around 1200 elements each as parameters. The parameters are around 220K in total. This is taking a...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
0
by: mantrid | last post by:
I was thinking along these lines initially but didnt know much about arrays. So thought the easiest way was to use two separate fields. However the two fields match, in that the commar separated...
2
by: vikramkumar | last post by:
I have two arrays,i want to take out common elements from those two arrays in a single statement, for example ; two arrays are my @a = (1, 3 ,4 ,7 ); my @b = (2 , 3 ,6 , 7); i want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.