Count Dracula Count Dracula - 3 months ago 10
PHP Question

getting the value of text field executed through a for loop using php

I have created 3 text fields which are displayed through a for loop. Now my concern is how will I get the values inputted to those text fields. Here's the code. Thank you.

<?php
echo '<form method = "post" action = "http://localhost:8080/sample.php">';

for($a = 0; $a < 3; $a++){
echo '<input type = "text" name = "box"></br>';
}
echo'<input type = "submit" name = "submit" value = "submit">';

if(isset($_POST['submit'])){
$square = $_POST['box'];
echo $square;
}
echo'</form>';
?>

Answer

Like Count Dracula suggested you could do something like this

<?php
echo '<form method = "post" action = "http://localhost:8080/sample.php">';

for($a = 0; $a < 3; $a++){
echo '<input type = "text" name = "box' . $a . '"></br>';
}
echo'<input type = "submit" name = "submit" value = "submit">';

and them you could access $_POST['box0'] or $_POST['box1'].

Hope this helps. Good Luck :)

Comments