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

	 ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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