Jump to content

Can you put a FORM and Input box in a FOR loop


kpetsche20

Recommended Posts

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>";
	}

	 ?>

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..

 

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.