Page 1 of 1

Accessing repetative variables from a form

Posted: Fri Jan 10, 2003 11:34 am
by kendall
Hi,

I have a form in which i collect consecutive email and passwords
i.e. email1 pass1 email2 pass2
which i would then insert into a database

so far i have

$x=1;
while($x<=count($_POST)){
if(array_key_exists("Email".$x,$_POST)){
$Email = 'Email'.$x;
$Pass = array_push($_POST,$_POST['Password'.$x]);
$account[$Email]=array_push($Pass);
$x++;
}

}
while(list($k,$val)=each($account)){
echo "Email: ".$k." Password: ".$val."<br>";
// Note using this to test how the calues would come out
}
exit;
}

but im getting a timeout

im trying to figure out a simpler way but dont quite have the nail on the head

any suggestions?

Was there a way in the form i could have an array of the values already defined?
thus email1 email2 pass1 pass2 would be Email[] array Pass[] array

Accessing repetative variables from a form

Posted: Fri Jan 10, 2003 11:37 am
by kendall
opps

that line should be

$account[$Email]=$Pass;

Posted: Fri Jan 10, 2003 5:22 pm
by volka
try this one

Code: Select all

<html><body>
<p><table border="1">
	<tr><th>email</th><th>password</th></tr>
<?php
if (isset($_POST['ep']))
{
	foreach($_POST['ep'] as $entry)
		echo '<tr><td>', $entry['email'], '</td><td>', $entry['pass'], '</td></tr>';
}
?></table></p>


<form method="POST">
	email:<input type="text" name="ep[0][email]" /> password:<input type="text" name="ep[0][pass]" />
	<br/>
	email:<input type="text" name="ep[1][email]" /> password:<input type="text" name="ep[1][pass]" />
	<br/>
	email:<input type="text" name="ep[2][email]" /> password:<input type="text" name="ep[2][pass]" />
	<br/>
	<input type="submit"/>
</form>
</body></html>