Mohammadali mirahamed Mohammadali mirahamed - 2 months ago 5x
PHP Question

how to echo input text in For{}

I write below code and put an html input text in for :

echo '<input type="text" name="subject">';

but when i want to echo the that value I type in to the above text box
it returns "" nothing

echo $_POST['subject'];

I have

<form name="form1" method="post" action="index.php">

Tag top of this codes ?

Sorry if I had Mistake


Make the input as array and read the values in PHP using loop like below.

HTML code :

<form name='myForm' action='index.php' method="post">
     for {$i=i;$i<5;$i++} {
           echo "<input type='text' name='subject[]'>";

PHP Code :

$subjectArray = $_POST['subject'];
foreach($subjectArray as $key => $val) {
     if($val != "") {  
         echo $key."==".$val."<br>";