homepage Welcome to WebmasterWorld Guest from 54.197.94.241
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Posting a form in a loop
malcolmcroucher




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

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)) {

$activityid=$row["activityid"];
$activityname=$row["activityname"];

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 :

book.php?activity=1&submit=Book+Now&activity=2&activity=3&activity=4&activity=5

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

 

Anyango




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

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]

stuartc1




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved