Alicia Posted March 24, 2009 Share Posted March 24, 2009 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 https://forums.phpfreaks.com/topic/150846-capture-array-problem/ Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 First, use long tags <?php and not short tags <? Surrounding variables inside single quotes don't get translated into values. echo $_POST['textfield'.$i]; Link to comment https://forums.phpfreaks.com/topic/150846-capture-array-problem/#findComment-792426 Share on other sites More sharing options...
sasa Posted March 24, 2009 Share Posted March 24, 2009 first name is must be "textfield1" not "textfield" Link to comment https://forums.phpfreaks.com/topic/150846-capture-array-problem/#findComment-792432 Share on other sites More sharing options...
Alicia Posted March 24, 2009 Author Share Posted March 24, 2009 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 https://forums.phpfreaks.com/topic/150846-capture-array-problem/#findComment-792446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.