Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Posting a form in a loop



8:10 am on Oct 29, 2008 (gmt 0)

5+ Year Member

Im creating a form in a loop and then using get to pass a variable.

The problem is it is posting multiple variables :

while ($row = mysql_fetch_assoc($r)) {


echo "<tr bgcolor=",$bgcolor," ><td width='310' align='center' > Interested </td><td> <form action='book.php' method='get'>";
echo "<input type ='hidden' name='activity' value=",$activityid," />
<input type='submit' name='submit' value='Book Now' /> </td></tr>
"; }

The if you examine my header it looks like this :


which means it is posting all the activities if i am not mistaken ?


8:49 am on Oct 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

If you intend to only use 1 row from mysql result then put a LIMIT 1 in your query, or remove your while loop. And i think "<form>" and "</form>" should be outside your loop

[edited by: Anyango at 8:50 am (utc) on Oct. 29, 2008]


3:32 pm on Oct 30, 2008 (gmt 0)

10+ Year Member

As Anyango already said, if all form fields are going as one form submissions you need to for tags outside the loop. But that may not help the problem at hand. My suggestion is to convert the field names to arrays, for example:

it currently is:
<input type ='hidden' name='activity'

change to :
<input type ='hidden' name='activity[]'

I'd also recommed changing the action to POST - GET is probably not the best option for forms (unless you have a good reason to us it)

However, if you actually do want to have multiple different forms, then just give each form a unique form name tag value.


Featured Threads

Hot Threads This Week

Hot Threads This Month