kpetsche20 Posted May 13, 2008 Share Posted May 13, 2008 Hey, is it possible to put a form inside a for loop. When I execute this script when I click the submit button it brings me to index.php?button=Submit instead of the action URL <?php $sql = "SELECT * FROM subscriptions"; $run = mysql_query($sql); for($x=0; $x < mysql_num_rows($run); $x++) { $data = mysql_fetch_array($run); echo " <form name=\"form\" action=\"index.php?p=paypal\"> <tr><td><b>".$data['name']."</b></td></tr><tr> <td>".$data['description']."<br></td> <tr> <td>$".$data['price']."<br></td> </tr> <tr> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></form><br><br><br></td> </tr>"; } ?> Quote Link to comment Share on other sites More sharing options...
radar Posted May 13, 2008 Share Posted May 13, 2008 Begin your corp outside of the for loop, and close it on the other side of the for loop. this way the form will always show up, but the information in between it wont.. Something about the for loop messes with forms (ive never gotten it to work the way you have it) but works flawlessly the way i said.. Quote Link to comment Share on other sites More sharing options...
kpetsche20 Posted May 13, 2008 Author Share Posted May 13, 2008 Problem is I need the form to change depending on what subscription is selected Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 yes, i use a similar method to the one you've posted. you might want to give each form a unique name, e.g., echo "<form name='form$x' action='whatever.php'>"; Quote Link to comment Share on other sites More sharing options...
kpetsche20 Posted May 13, 2008 Author Share Posted May 13, 2008 The names and prices change depending on what subscription is selected Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 okay. you'll need to put the values you want to pass into visible or hidden form fields. i suggest that you only pass product id in a hidden field; don't rely on what you get from the browser to set the price. Quote Link to comment Share on other sites More sharing options...
kpetsche20 Posted May 13, 2008 Author Share Posted May 13, 2008 I know that but when I hit the submit button it redirects me to http://www.webmasterfreehost.com/sportsbook/members/index.php?button=Submit instead of http://www.webmasterfreehost.com/sportsbook/members/index.php?p=paypal Quote Link to comment Share on other sites More sharing options...
radar Posted May 13, 2008 Share Posted May 13, 2008 Thats why you throw the form outside of the loop... because it'll go to paypal all the time regardless... then you'll get the pricing information and such from the $_POST... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 I know that but when I hit the submit button it redirects me to http://www.webmasterfreehost.com/sportsbook/members/index.php?button=Submit instead of http://www.webmasterfreehost.com/sportsbook/members/index.php?p=paypal i think we ran into a similar problem the other day, trying to use an action URL with a value appended. since you're posting anyway, why not pass p in a hidden form element instead of passing it as part of the URL in the form action? just noticed: another issue is that you don't define the form method='POST' (assuming you want post). also: can we see the latest code? Quote Link to comment Share on other sites More sharing options...
kpetsche20 Posted May 13, 2008 Author Share Posted May 13, 2008 I put the form tags outside the for loop and it does the same thing <tr> <td bgcolor="#FFFFFF"> <table width="500px"><tr> <td>Name</td> </tr> <form name=\"form\" action=\"index.php?p=paypal\"> <?php $sql = "SELECT * FROM subscriptions"; $run = mysql_query($sql); for($x=0; $x < mysql_num_rows($run); $x++) { $data = mysql_fetch_array($run); echo " <tr><td><b>".$data['name']."</b></td></tr><tr> <td>".$data['description']."<br></td> <tr> <td>$".$data['price']."<br></td> </tr> <tr> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /><br><br><br></td> </tr>"; } ?></form> </table> <p> </p> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 there's nothing wrong with creating multiple forms in a loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.