0

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 /

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rahul8590
0

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.

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

Edited by rajarajan07: n/a

0

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>

Edited by vibhaJ: n/a

0

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)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.