user3467436
user3467436

Reputation: 1

creating multiple input box by using for loop and accessing them store their values in database

how to create an array of input box which has name in iterative order like name=name1,name2 ..... like and i want access them on next page by using PHP

    echo"<form action='addprogrammerdetails.php' action='post'>";
                echo"<table border='0' class='corner' width='600'>";
                echo"<tr>";
                echo"<td>";
                echo"&nbsp;";
                echo"</td>";
                echo"</tr>";
                echo"<tr>";
                echo"<td colspan='2' bgcolor='#E57614'>";
                echo"PROGRAMMER DETAILS";
                echo"</td>";
                echo"</tr>";

                session_start();
                $nprog=$_SESSION['nprog'];
                for($i=1;$i<=$nprog;$i++)
                {
                    echo"<tr>";
                    echo"<td>";
                    echo"<table>";
                    echo"<tr>";
                echo"<td width='300'>";
                echo"Programmer Number:";
                echo"</td>";
                echo"<td>";

                echo"<input type='text' name='no[]' value='$i' disabled/>";
                echo"</td>";
                echo"</tr>";
echo"</table>";

                echo"</td>";

                echo"</tr>";

                }
                echo"<tr>";
                echo"<td colspan='2' align='center'>";
                echo"<input type='submit' value='SUBMIT'/>";
                echo"</td>";
                echo"</tr>";
                echo"</table>";
                echo"</form>";
                ?>

Upvotes: 0

Views: 391

Answers (1)

Nauphal
Nauphal

Reputation: 6182

If you name your element with [], you can access it as an array in PHP

$no1 = $_POST['no'][0];
$no2 = $_POST['no'][1];
$no3 = $_POST['no'][2];

OR

foreach($_POST['no'] as $values) {
  // do something with $value
}

Upvotes: 1

Related Questions