Jump to content

capture array problem


Alicia

Recommended Posts

Hi guys,

 

I am having problem capturing the values posted from this simple form. Can guru please advise on this :

 

<form id="form1" name="form1" method="post" action="array2.php">
  <label>
  <input type="text" name="textfield" id="textfield" />
  </label>
  <p>
    <label>
    <input type="text" name="textfield2" id="textfield2" />
    </label>
</p>
  <p>
    <label>
    <input type="text" name="textfield3" id="textfield3" />
    </label>
</p>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Submit" />
    </label>
  </p>
</form>


 

my php file to test the output but none of it works,. =(

 

<?
$check2 = 4;
for($i=1;$i<$check2;$i++) { 
echo $_POST['textfield$i'];
//${$textfield$i]} = $_POST['textfield$i'];
echo ${$textfield[$i]};
echo "{$_post['textfield']['$i']}<br />";
//echo $_POST['textfield2'];
echo ${$_POST['textfield$i']};
echo $i;
echo $_post['textfield']['$i'];

print_r($_post);
}
?>

 

Thanks

Link to comment
Share on other sites

Thanks guys... now another question need your help..

 

how can I put the textfield inside the while loop so it will show something like textfield1, textfield2 and etc without using for loop ?

 

I tried this one but the number the number assigned to these elements are all not in correct order.. i think there is some prob with my code.. please advise :

<form id="form1" name="form1" method="post" action="class3.php">
                                <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                  <? 
							  $i = 1;
								$question = mysql_query("SELECT * FROM classquestion WHERE status ='Active'");
								while($question2 = mysql_fetch_array($question))
								{
								?>
                                  <tr>
                                    <td>
                                    <? echo $question2['question']; ?>                                    <input name="question<? echo $i++?>" type="hidden" id="question<? echo $i++?>" value="<? echo $question2['question']; ?>" /></td>
                                  </tr>
                                  <tr>
                                    <td><label>
                                      <textarea name="answer<? echo $i++;?>" id="question" cols="80" rows="5"></textarea>
                                      </label></td>
                                  </tr> <?
                                  }
							  ?>
                                  <tr>
                                    <td><label>
                                      <input type="submit" name="button" id="button" value="Submit" />
                                    </label></td>
                                  </tr>
                                </table>
							</form>

 

I want it arrange the number accordingly like question1 answer1 then question2 and answer2 and etc.. but now, what I got is question1 then answer4, question3 and answer2 .. all are not in proper order and there is no way i can echo the output in the correct order.

 

please advise.

 

Link to comment
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.