Jump to content

Making New Variables Depending On Size Of A Form


Recommended Posts

I have made a script that generates an html form based on the number of users in a table...Here is the code:

<form action="addpayment.php" method="post" name="addpayment">Company Name: <input name="company" type="text" /> <br />Item Purchased: <input name="item" type="text" /> <br />	<br />How much did each person pay?<br />			<?phpinclude("selectusers.php");	for ($k=0; $k<=$num_users - 1; $k++)	{echo $users[$k] . " paid: £ <input name=\"" . "person" . ($k+1) . "paid" . "\" type=\"text\" /> <br />";}<br /><input type="submit" value="Submit" /></form>

$users is an array containing all the names of the users in table$num_users is an integerLater on I will want variables that say how much each user has paid and how much they oweE.g. $person1_paid and $person1_topayThese variables will need to be created based on the number of fields in the form as the input names of the text boxes will go:person1paidperson2paidperson3paidetcso I will need some code that goes like

for ($i=1; $i<=$num_users; $i++){$person"$i"paid = $POST['person"$i"paid'];}

where "$i" is the variable $i as a string

Link to comment
Share on other sites

for ($i=1; $i<=$num_users; $i++) {	$person[$i]['paid'] = $POST["person{$i}paid"];	$person[$i]['topay'] = $POST["person{$i}topay"];}


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...