Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Checkbox Name --> How do I pass the vaules to a script to..

Status
Not open for further replies.

Lynux

MIS
Aug 3, 2001
33
US
I am dynamically creating a form with check boxes and hidden fields. The form
text names and hidden field names are being dynamically created depending on the button clicked on
my page (being pulled from my mysql database).

I am then needing to insert the responses to the check boxes into a users table.

my problem is:
(1) when a form check box name is dynamically generated... and that information is needing to be
passed to my script that runs the SQL to insert it into the database how do I assign the variable
names dynamically?

below is an example of the code that dynamically generates the form elements:
<?php
// roll through database and get competencies
while ($compdisplayarray = mysql_fetch_array($compdisplay)) {
$compdisplayarray1 = $compdisplayarray[&quot;Competency&quot;];
$compdisplayarray2 = $compdisplayarray[&quot;Cluster_ID&quot;];
$compdisplayarray3 = $compdisplayarray[&quot;Competency_ID&quot;];
echo &quot;<tr><td>&quot;.$compdisplayarray1 .&quot;</td><td><select name=re&quot;.$compdisplayarray2.$compdisplayarray3
.&quot;><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option></select>&quot;
.&quot;<input type=hidden name=cl&quot;.$compdisplayarray2 .&quot; value=&quot;.$compdisplayarray2 .&quot;>&quot;
.&quot;<input type=hidden name=co&quot;.$compdisplayarray3 .&quot; value=&quot;.$compdisplayarray3 .&quot;> </td></tr>&quot;;
}
?>

after this is generated and answered by the user, they submit to a script that needs to run the following SQL:

INSERT INTO userscores (user, cluster_ID, competency_ID, score)
VALUES (this is where I need to use the varibles wich I do not know in advance);

I know this is possible and done quite often by developers but I am unsure how to aproach it. I know it more than likely
involves the $HTTP_POST_VARS function... but that is about as far as I have taken it.

Thanks in advance! :) =================================
Imagination is more important than knowledge.
(A.E.)
 
After posting,
Code:
$HTTP_POST_VARS
is an array containing the variable names and values. You could scan through this array for recognisable variable names, but this seems to me to be an unnecessary headache. I suggest adding a hidden field to your form loop like this (assuming a 1-to-1 relationship between cluster_id and competency_id):

Code:
echo &quot;<INPUT&quot;;
echo &quot; TYPE=\&quot;hidden\&quot;&quot;;
echo &quot; NAME=\&quot;active[&quot;.$compdisplayarray2.&quot;]\&quot;&quot;;
echo &quot; VALUE=\&quot;&quot;.$compdisplayarray3.&quot;\&quot;&quot;;
echo &quot;>&quot;;

Then in your process script, you can use something like
Code:
while (list($cluster_id,$competence_id)=each($active)) {
  // your variables available as
  // ${&quot;re&quot;.$cluster_id.$competence_id} etc.
}

Hope you can see the sense of this. If you don't have a 1-to-1 relationship (eg more than one competence per cluster), you could add two hidden fields instead of one.

-Rob
 
Ill give that a try!.. Thanks Rob! =================================
Imagination is more important than knowledge.
(A.E.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top