prathameshkakade Posted July 31, 2013 Share Posted July 31, 2013 Hello everyone.I am learning arrays in PHP.I tried to take 6 text inputs and store it ina a array and then display when we click submit button.But I am not getting output.Below is my code.Please help me out. <html> <head> <title> List Function </title> </head> <body> <?php if(isset($_POST['posted'])) { for($count=0;$count<=5;$count++) { $a = $_POST['hidden'][$count]; echo "$a<br/>"; } } ?> <form method = "POST" action = "listfunction.php"> <input type = "hidden" name = "posted" value = "true"/> <?php for($counter=0;$counter<=5;$counter++) { echo "<input type = 'text' name = '$array[$counter]'><br/>"; echo "<input type = 'hidden' name = 'hidden[]' value = '$array[$counter]'>"; } ?> <input type = "submit" value = "submit"/> </body> </html> Thank you. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 31, 2013 Share Posted July 31, 2013 Because $array[$counter] is not defined and has no value. What are you trying to do? Quote Link to comment Share on other sites More sharing options...
prathameshkakade Posted August 4, 2013 Author Share Posted August 4, 2013 Well just tell me how to take inputs,store it in array and then display it when clicked 'submit'. Quote Link to comment Share on other sites More sharing options...
adoado Posted August 5, 2013 Share Posted August 5, 2013 You've actually done it! $myArray = array(); foreach(iterator here){ $myArray[iterator] = XX } That's pseudocode though Quote Link to comment Share on other sites More sharing options...
prathameshkakade Posted August 6, 2013 Author Share Posted August 6, 2013 You've actually done it! $myArray = array(); foreach(iterator here){ $myArray[iterator] = XX } That's pseudocode though still not getting it. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 6, 2013 Share Posted August 6, 2013 Well just tell me how to take inputs,store it in array and then display it when clicked 'submit'. Kind of demanding and uninformative: if(isset($_POST['posted'])) { print_r($_POST); } ?> <form method = "POST" action = "listfunction.php"> <input type = "hidden" name = "posted" value = "true"/> <?php for($counter=0;$counter<=5;$counter++) { echo "<input type = 'text' name = 'text[]'><br/>"; echo "<input type = 'hidden' name = 'hidden[]' value = '$counter whatever you want'>"; } ?> <input type = "submit" value = "submit"/> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.