1

Hello DaniWeb.

It's my first time to do PHP, so please bear with me.
I've read books and viewed tutorials just to solve this one.

I want to have a variable number of text fields. Then, I want to have the contents of those text fields loaded in an array in &_POST, because I want to be able to use those values as an array in the next page.
How do I implement that?

I tried this one, but it doesn't work:

<?php 
	$n = $_POST["var_n"];
?>

<html>
<body>
	<br>
	<center><h2>Reverse Array</h2></center>
	
	<form action="Result.php", method="post">
		<center>				
			<br>Please input the contents of the array: 
			<br>
				<?php 
					$the_array = array_fill(0, $n, 1);
					createTextBoxes($the_array, $n);
					//$array_ref = array_fill(0, $n, 1);
				?>
			<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=\"\$the_array[", $i, "]\" size=\"3\">";
	}
?>

Edited by boyRevolt: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by saiprem
0

Hi I hope this will give you a little information regarding how to use an array in next page.....

<?php 
	$n = 6;//$_POST["var_n"];
	echo "<pre>";
	print_r($_POST);
	echo "</pre>";
?>

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

If you want to send the data to next page, add method='next.php' in form tag, in next.php page add the code print_r($_POST);

you can view the posted contents...

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.