By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,572 Members | 2,949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,572 IT Pros & Developers. It's quick & easy.

For loops to show an amount of text fields based on a variable quantity

P: 3
Hi,

I've been trying to set up a php system to calculate and order and recieve delivery address/s. It's going pretty well so far but I having trouble with one particular part.

I've been trying to use a for loop to show a number of delivery address forms based on the quantity of the product ordered, (sounds like a strange thing to do but the product is intended for people so send to friends as a novelty item)

I have created a php file of what I thought it should be just using a fix value of quanty just so I can figure out what the code will be and I can get it to display text for the quantity e.g address1, address 2 e.t.c but can't get it to display text input boxes.

I think the problem is that when it loops the form the adress fields have the same name.

I am working on an Windows XP machine and the server for the site has the latest stable release of php.

The error is "unexpected T_STRING" for the first line where i try and use an input field.

Below is the relevent code, most of the adress form is commented out as I'm sure once I get one to workt he rest will follow fairly easily.

Any help would be much appreciated, thanks
[PHP]
<?php
$table=1;
$qty=3;
for ($table>1; $table<=$qty; $table++)
{
print "Address";
print $table;
print "<p>";
print "<p>Name: <input type="text" name="name">";
//print "<p>Address line 1: <input type="text" name="address1" />";
//print "<p>Address line 2: <input type="text" name="address2" />";
//print "<p>Address line 3: <input type="text" name="address3" />";
//print "<p>Post Code: <input type="text" name="postcode" />";
}
?>
[/PHP]
Nov 17 '06 #1
Share this Question
Share on Google+
4 Replies


TheMadMidget
P: 98
[PHP]
for ($table>1; $table<=$qty; $table++)
[/PHP]
"$table>1" this should be a declaration like "$table = 1"
Nov 17 '06 #2

P: 3
Thanks for your help, but I still have the same problem.
Nov 17 '06 #3

ronverdonk
Expert 2.5K+
P: 4,258
Is this a form that should be submitted or just an overview of addresses?

If this is a form to be submitted I miss the <form> tags.
If not a form, what are you doing with the <input> fileds, how do you want to handle them?

When the former is clear we can look at the solution.

Ronald :cool:
Nov 17 '06 #4

P: 3
This is prototype for part of the order form, its once the user has chosen how many units they want to order and I'm trying to make it give them spaces to write in a number of delivery adresses based on the quantity of the order.
Many thanks for looking at my post.
Rob
Nov 17 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.