0

I'm trying to create a loop to create 20 text input fields for username & 20 text input fields for password and my current attempt is listed below. It isn't working & if I view source the $i variable doesn't seem to be expanding properly.

<?php
    for ($i = 0; $i < 20; $i++) {
        echo ('<input type="text" id="username . $i" class="userInfo" value="<?php echo $userName1; ?>" />');
        echo ('<input type="text" id="password . $i" class="userInfo" value="<?php echo $password1; ?>" />');
    }
?>
6
Contributors
6
Replies
19
Views
5 Years
Discussion Span
Last Post by diafol
1
echo "<input type='text' id='username'". $i." class='userInfo' value='".$userName1."'/>";

use the above code i hope you will get solved your issue thanks!

0

Try this
input_form.php

<?php
	echo "<form method = 'POST' action = 'process.php'>";
	for($counter = 0; $counter < 10; $counter++)
	{
		echo "<input type = 'text' name = 'username[]' class = 'class_name'/><br/>";
		echo "<input type = 'password' name = 'password[]' class = 'class_name'/><br/>";
	}
	echo "<input type = 'submit' value = 'SEND'/>";
	echo "</form>";
?>

Now to process inputs from the above form, do something like this.
process.php

<?php
	$usernames = array();
	$passwords = array();
	
	$usernames = $_POST['username'];
	$passwords = $_POST['password'];
	
	for($counter = 0; $counter < sizeof($usernames); $counter++)
	{
		echo "Username #".($counter + 1).": ".$usernames[$counter]."<br />";
		echo "Password #".($counter + 1).": ".$passwords[$counter]."<br />";
	}
?>
0

i want to input number of form i want to generate please i need a code that does that.
eg. if i want to register 50 students at a time with the following fileds first name lastname sex addres class date of birth and submit. if i submit it should go to the database at once.

0

i want to input number of form i want to generate please i need a code that does that.
eg. if i want to register 50 students at a time with the following fileds first name lastname sex addres class date of birth and submit. if i submit it should go to the database at once.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.