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

Difficulty with passing variables. 1

Status
Not open for further replies.

Haraldo

Programmer
Jun 9, 2003
41
GB
I am relatively new to php3. So i could be going about this the wrong way. Bare with me i need to set the scene!

I am having trouble picking up passed variables from an input form. The form collects address information. I have therefore given the user the choice of how many addresses he wants to have displayed. He can choose 2 for instance press go and it will load up the page again but displays 2 address boxes. So i have to generate the correct number of variables and make sure i pass the information correctly, see below: (this is the skeleton) Passing the variables works fine. But how do i pick them up in the php3 page i pass it to correctly?

<?php
// i've put a limit on the amount of boxes that can appear
if ( $fields > 0 && $fields < 21) {

// loop which concatinates a number onto each field
while ($i < $fields) {
$string = &quot;make&quot; . $i;
$string2 = &quot;colour&quot; . $i;
$string3 = &quot;reg&quot; . $i;
$string4 = &quot;surname&quot; . $i;
$string5 = &quot;fname&quot; . $i;
$string6 = &quot;housename&quot; . $i;
$string7 = &quot;town&quot; . $i;
$string8 = &quot;postcode&quot; . $i;
$string9 = &quot;hnumber&quot; . $i;
$string10 = &quot;wnumber&quot; . $i;
$string11 = &quot;mobile&quot; . $i;
$string12 = &quot;email&quot; . $i;
$string13 = &quot;road&quot; . $i;

echo&quot;
<tr>
<td>Personal Details</td>
</tr>
<tr>
<td>Surname*</td>
// input fields that use the incremented variables
<td><input name=\&quot;$string4\&quot; type=\&quot;text\&quot;>
<input name=\&quot;numfields\&quot; type=\&quot;hidden\&quot; value=\&quot;$fields\&quot;/></td>
</tr>
<tr>
<td>First Name*</td>
<td><input name=\&quot;$string5\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr >
<td>House Name/No*</td>
<td><input name=\&quot;$string6\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Road*</td>
<td><input name=\&quot;$string13\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr class=\&quot;textMain\&quot;>
<td>Town/City*</td>
<td><input name=\&quot;$string7\&quot; type=\&quot;text\&quot; id=\&quot;town\&quot; size=\&quot;40\&quot; /></td>
</tr>
<tr>
<td>Postcode*</td>
<td><input name=\&quot;$string8\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Home number*</td>
<td><input name=\&quot;$string9\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Work Number*</td>
<td><input name=\&quot;$string10\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Mobile*</td>
<td><input name=\&quot;$string11\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Email*</td>
<td><input name=\&quot;$string12\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Car Details</td>
</tr>
<tr><td>Make of Car*</td>
<td><input name=\&quot;$string\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Colour*</td>
<td><input name=\&quot;$string2\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
<td>Reg. of Car*</td>
<td><input name=\&quot;$string3\&quot; type=\&quot;text\&quot;></td>
</tr>
<tr>
</tr>&quot;;
// increment the while loop
$i = $i + 1;
}
}
?>

However when i try to use these variables on the php3 page the info gets sent to, i am unable to exract the info in a loop for example adding an incremented number to the end of the variable as i have done so on the first form. So the only way i have been able to do it was by using &quot;if&quot; statments and the following variables:

These are the field names from the previous form with the increment.
$fname0, &wnumber0 etc all the way up to:
$fname19, &wnumber19 Using if statments i have had to make the number of boxes i generate finite- you get me! Takes ages if i need to update the stuff. All i want is a loop but i just don't get how i am supposed to get the info out of the variable. I've been rebuilding the variable to extract the info but i always get stuck.

I've tryed $input(name not important) = $fname . $i; (where $i is the incrementing number.) Just doesn't understand. I get no errors just the value of the incremented number.

If anyone could help me you would be my savour! I'm a small time web developer, trying to get experience with php. I hope what i have said is clear enough. Thanks for your time,
Harry
 
$i=0;
while($i<21)
{
$name[$i]=$_POST['name'.$i];
$i++;
}


does this work? i dont know whether PHP has support for $_POST, check it out...

Known is handfull, Unknown is worldfull
 
Thanks so much for you help and quick responses...

YOU HAVE SOLVED MY PROBLEM

I know it wasn't rocket science but if you don't know what to do you round in circles,
Thanks guys, brilliant

Later
H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top