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 = "make" . $i;
$string2 = "colour" . $i;
$string3 = "reg" . $i;
$string4 = "surname" . $i;
$string5 = "fname" . $i;
$string6 = "housename" . $i;
$string7 = "town" . $i;
$string8 = "postcode" . $i;
$string9 = "hnumber" . $i;
$string10 = "wnumber" . $i;
$string11 = "mobile" . $i;
$string12 = "email" . $i;
$string13 = "road" . $i;
echo"
<tr>
<td>Personal Details</td>
</tr>
<tr>
<td>Surname*</td>
// input fields that use the incremented variables
<td><input name=\"$string4\" type=\"text\">
<input name=\"numfields\" type=\"hidden\" value=\"$fields\"/></td>
</tr>
<tr>
<td>First Name*</td>
<td><input name=\"$string5\" type=\"text\"></td>
</tr>
<tr >
<td>House Name/No*</td>
<td><input name=\"$string6\" type=\"text\"></td>
</tr>
<tr>
<td>Road*</td>
<td><input name=\"$string13\" type=\"text\"></td>
</tr>
<tr class=\"textMain\">
<td>Town/City*</td>
<td><input name=\"$string7\" type=\"text\" id=\"town\" size=\"40\" /></td>
</tr>
<tr>
<td>Postcode*</td>
<td><input name=\"$string8\" type=\"text\"></td>
</tr>
<tr>
<td>Home number*</td>
<td><input name=\"$string9\" type=\"text\"></td>
</tr>
<tr>
<td>Work Number*</td>
<td><input name=\"$string10\" type=\"text\"></td>
</tr>
<tr>
<td>Mobile*</td>
<td><input name=\"$string11\" type=\"text\"></td>
</tr>
<tr>
<td>Email*</td>
<td><input name=\"$string12\" type=\"text\"></td>
</tr>
<tr>
<td>Car Details</td>
</tr>
<tr><td>Make of Car*</td>
<td><input name=\"$string\" type=\"text\"></td>
</tr>
<tr>
<td>Colour*</td>
<td><input name=\"$string2\" type=\"text\"></td>
</tr>
<tr>
<td>Reg. of Car*</td>
<td><input name=\"$string3\" type=\"text\"></td>
</tr>
<tr>
</tr>";
// 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 "if" 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 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 = "make" . $i;
$string2 = "colour" . $i;
$string3 = "reg" . $i;
$string4 = "surname" . $i;
$string5 = "fname" . $i;
$string6 = "housename" . $i;
$string7 = "town" . $i;
$string8 = "postcode" . $i;
$string9 = "hnumber" . $i;
$string10 = "wnumber" . $i;
$string11 = "mobile" . $i;
$string12 = "email" . $i;
$string13 = "road" . $i;
echo"
<tr>
<td>Personal Details</td>
</tr>
<tr>
<td>Surname*</td>
// input fields that use the incremented variables
<td><input name=\"$string4\" type=\"text\">
<input name=\"numfields\" type=\"hidden\" value=\"$fields\"/></td>
</tr>
<tr>
<td>First Name*</td>
<td><input name=\"$string5\" type=\"text\"></td>
</tr>
<tr >
<td>House Name/No*</td>
<td><input name=\"$string6\" type=\"text\"></td>
</tr>
<tr>
<td>Road*</td>
<td><input name=\"$string13\" type=\"text\"></td>
</tr>
<tr class=\"textMain\">
<td>Town/City*</td>
<td><input name=\"$string7\" type=\"text\" id=\"town\" size=\"40\" /></td>
</tr>
<tr>
<td>Postcode*</td>
<td><input name=\"$string8\" type=\"text\"></td>
</tr>
<tr>
<td>Home number*</td>
<td><input name=\"$string9\" type=\"text\"></td>
</tr>
<tr>
<td>Work Number*</td>
<td><input name=\"$string10\" type=\"text\"></td>
</tr>
<tr>
<td>Mobile*</td>
<td><input name=\"$string11\" type=\"text\"></td>
</tr>
<tr>
<td>Email*</td>
<td><input name=\"$string12\" type=\"text\"></td>
</tr>
<tr>
<td>Car Details</td>
</tr>
<tr><td>Make of Car*</td>
<td><input name=\"$string\" type=\"text\"></td>
</tr>
<tr>
<td>Colour*</td>
<td><input name=\"$string2\" type=\"text\"></td>
</tr>
<tr>
<td>Reg. of Car*</td>
<td><input name=\"$string3\" type=\"text\"></td>
</tr>
<tr>
</tr>";
// 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 "if" 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