scadran Posted August 5, 2007 Share Posted August 5, 2007 Hi guys I have a page in which i will ask the user to enter number of people. according to their answer I will create textbox the same amount as they gave the answer. they complete the text box and i want to send it to the other page by POST. how can I take them in a while loop by the next page? Can someone help me here are my codes: within the page which create the nested textboxes: $counter = 1; while ( $counter <= $no ) { echo "<input type=\"text\" name=\"".'a'."$counter\" size=\"6\"> "; $counter = $counter + 1; } ?> within the page which i want to recive them: $result = mysql_query("SELECT * FROM temp") or die(mysql_error()); $row = mysql_fetch_array($result); $cnt=1; $new_no = $row[6]; while ( $cnt <= $row[5] ) { $cd='a'.$cnt; $code = $_POST['$cd']; echo $code; $tyre_arr = mysql_query("select * from tyre where code='$code'") or die(mysql_error()); $tyre = mysql_fetch_array($tyre_arr); ?> I guess there should be something wrong with this line: $code = $_POST['$cd']; any idea? Quote Link to comment https://forums.phpfreaks.com/topic/63370-nested-post/ Share on other sites More sharing options...
dbo Posted August 5, 2007 Share Posted August 5, 2007 Well what is the script doing or not doing? Is there an error? This info should help us figure out where to look and what to look for. Quote Link to comment https://forums.phpfreaks.com/topic/63370-nested-post/#findComment-315841 Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 Dont know if i got it completely right but anyway. U can create a hidden input where u pass the number of people the user entered (or just use get for that). When u recieve them make a loop to get the data from post ex: $nrPpl = $_POST['nrpeople']; for($i=1; $i<=$nrPpl, $i++){ echo $_POST['input$i']; } I assumed u named the input boxes as input1, input2 etc. Hope it helped. Quote Link to comment https://forums.phpfreaks.com/topic/63370-nested-post/#findComment-315845 Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 Ok i just made a test and u can use count($_POST) to count the number of inputs u have, assuming u have only the input texts passed to post. So: $nrPpl = count($_POST); Also u may have a submit button which is also passed to post, so u can check: if(array_key_exists('submit', $_POST)){ $nrPpl = count($_POST) - 1; } else{ $nrPpl = count($_POST); } Quote Link to comment https://forums.phpfreaks.com/topic/63370-nested-post/#findComment-315849 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.