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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing generated input variables to the next page

Status
Not open for further replies.

shagymoe

Programmer
Apr 20, 2001
72
US
I have a php script which generates a list of modules to install or uninstall based on reading the directory names. So the page presents the user with something like this:
Code:
Text      Radio    Radio      Radio
          Button   Button     Button
--------------------------------------
Module1   Install  Uninstall  Ignore
Module2   Install  Uninstall  Ignore
Module3   Install  Uninstall  Ignore
Module4   Install  Uninstall  Ignore

As you can see, these are radio button choices and the "value" given to each row of buttons is the module name. I am not sure how to assign the $_POST variables on the next page since the "value"s were generated automatically. I think it is bad form to run the function which populated the module names again. There should be an easier way to pass the info to the next page..in an array or something. I'm just not sure what the best way would be. How do you pass a $_POST variable where the "value" is unknown before the script is run? OR How do you pass an array to the next page without using $_POST? I'm sure this is simple...I'm pretty green at web programming, but I've done quite a lot of system programming. Thanks for the help.
 
If you have a group of HTML form elements on a page and you name those elements with names that suggest array elements, then their values will be in $_POST as an array.

For example:

<form action=&quot;....&quot; method=&quot;POST&quot;>
<input type=&quot;test&quot; name=&quot;foo[]&quot;>
<input type=&quot;test&quot; name=&quot;foo[]&quot;>
<input type=&quot;test&quot; name=&quot;foo[]&quot;>
</form>

Then $_POST['foo'] will itself be an array.

This might be useful.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I just looked in the FAQs and saw the same thing...I think that will work, thanks for the help!
 
Hello,

I was looking at the above inquiry. But how do I get the script to automatically pass the variable to the next page?

Here's my script below;

<?php
$conn=mysql_connect(&quot;localhost&quot;,&quot;user&quot;,&quot;password&quot;)
or die(&quot;Could not connect &quot; . mysql_error());
//print &quot;Connected successfully&quot;;
mysql_select_db(&quot;mylogin&quot;,$conn) or die(&quot;Could not select database&quot;);
$sql = &quot;select userid from logins where userID='$userID' and passID = '$passID'&quot;;
$result=mysql_query($sql);
if (mysql_num_rows($result)!=0)
{

header(&quot;location:page2.php&quot;);

}else{

print &quot;<h2>Invalid Username or Password.</h2>&quot;;
}




?>

Any assistance will be helpful.

Thanks
KJ
 
It's considered bad form to coattail on another member's question. But I'll answer.

If you're using the &quot;Location&quot; header to jump the browser to another page, you have two choices.

If the amount of data to be passed is small, you can encode the data into the location header's URL:
header ('Location:
You can also use session variables.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top