Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/63370-nested-post/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/63370-nested-post/#findComment-315845
Share on other sites

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);
}

Link to comment
https://forums.phpfreaks.com/topic/63370-nested-post/#findComment-315849
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.