0

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>";
                ?>

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.