Well this might sound a bit ridiculous , i request the user to enter the no of names field to be generated and then i am successfully able to generate , but dont know how to go about saving those many names in the name column of my db.

initial html page

<form action="redirect.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />

redirect.php page

$val = $_POST['yourname'];

for ( $i = 0; $i < $val ; $i++)
{
?>
<form action="redirect1.php" method="post">
Name: <?php echo $i+1 ?>  <input type="text" name="yourname[]" maxlength="150" /><br />
<?php

} 
?>
<input type="submit" value="Submit" style="margin-top: 10px;" />

well i thought i would print the various names entered in redirect1.php and save it in db , any other ingenious ideas are welcomed /

Recommended Answers

All 4 Replies

How user will enter the name?
One by one or any other way?

If User will enter one by one , apply mysql query in second file.

Member Avatar for rajarajan2017
<html>
<body>
	<br>
	<center><h2>Array of textboxes</h2></center>
	<form action="Result.php" method="post">
		<center>				
			<br>Please input the contents of the array: 
			<br>
				<?php 
					$the_array = array_fill(0, 5, 1);
					createTextBoxes($the_array, 5);
				?>
			<br><input type="submit" value="Next">
		</center>
	</form>
</body>
</html>
				
<?php 
	function createTextBoxes($the_array, $n){
		for($i = 0; $i < $n; $i++)
			echo "<input type=\"text\" name=\"inp$i\" size=\"3\">";
	}
?>

The above code will help you to create 5 textboxes, you can just pass the variable of input get from the user instead of that 5 and create the no of textboxes. Click submit to collect the value on next page

noneed to redirect1.php page.
FORM tag should be outside of for loop.

<?php
if(isset($_REQUEST['Submit']) && isset($_REQUEST['name']))
{
	$allname = $_REQUEST['name'];
	for($i=0;$i<count($allname);$i++)
	{
		$q="insert into user(id,name) values('','".$allname[$i]."')";
		mysql_query($q);
	}
	header("location:initial.html");
	exit;
}

$val = $_POST['yourname'];
?>
<form action="" method="post">
<?php for ( $i = 0; $i < $val ; $i++){ ?>
Name: <?php echo $i+1 ?>  <input type="text" name="name[]" maxlength="150" /><br />
<?php } ?>
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>

thanks rajaranjan and vibhadevit , kudos to you for such solutions .
Well now i can insert it in one page itself , but i need that another page redirect1.php because i want to display things like Registration details .

i thought of using a cookie for that

$val = $_POST['yourname'];
setcookie("name",$val,time()+3600);

but i dont think this may panout , since many people would have disabled cookies which would be a problem later on .
the point is i want to pass these variable values to the next page or the current page if its possible in order to display the registration details (more like a summary)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.