ronniepeter Posted July 9, 2017 Share Posted July 9, 2017 <?phpif(isset($_POST['submit'])){$n=$_POST['t'];print "<form method=POST action=''>";for($i=0;$i<$n;$i++){print "<input type=text name=t$i>";}print "<input type=submit name=display value=Display>";print "</form>";}$arr=array();if(isset($_POST['display'])){//$n=$_POST['t'];for($i=0;$i<$n;$i++){$arr[$i]=$_POST['t'.$i];}print_r($arr);}?><form method=POST action=''><label>Enter the range:</label><input type=text name='t'><input type=submit name=submit value=Submit></form>--------------------------------------------------------------------------------------The purpose of this code is to input a range value in a textbox. According to that text boxes will be generated by the PHP code dynamically. The values entered in the text box is stored in an array and the values in the array should be finally printed. The problem in this code is, the range value entered in the text box is not available in the display isset so that array variable is not able to accept the values entered in the text box. For the first isset called submit, the $n variable is supplying the range value but for the second isset display, the $n variable value is not available. Help.... Quote Link to comment https://forums.phpfreaks.com/topic/304278-issues-with-isset/ Share on other sites More sharing options...
Jacques1 Posted July 9, 2017 Share Posted July 9, 2017 Is this homework? A personal exercise? A real website? The reason why I'm asking is that the whole approach is very awkward and should be changed altogether. Why not use a textarea with one number per line? If you absolutely must use this approach because your teacher or boss told you so, then submit the numbers as an array instead of using those weird numbered parameters: <form method="post"> <!-- PHP will put those parameters into a single array accessible through $_POST['t'] --> <input type="number" name="t[]"> <input type="number" name="t[]"> <input type="number" name="t[]"> <input type="number" name="t[]"> <input type="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/304278-issues-with-isset/#findComment-1548116 Share on other sites More sharing options...
ronniepeter Posted July 9, 2017 Author Share Posted July 9, 2017 Thank you very much for the reply Mr. Guru. I will surely change the code according to your suggestion. But my problem is still persisting. The problem is, for the isset display, the $n variable that I used to accept the range value is not made available. If I substitute a value instead of the $n variable that I have used in the for loop of isset display, it works and the array prints the values. Is there any way to make the value of the $n variable available in isset display. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/304278-issues-with-isset/#findComment-1548117 Share on other sites More sharing options...
aebstract Posted July 9, 2017 Share Posted July 9, 2017 Thank you very much for the reply Mr. Guru. I will surely change the code according to your suggestion. But my problem is still persisting. The problem is, for the isset display, the $n variable that I used to accept the range value is not made available. If I substitute a value instead of the $n variable that I have used in the for loop of isset display, it works and the array prints the values. Is there any way to make the value of the $n variable available in isset display. Thank you. //$n=$_POST['t']; because you have // in front of it? Quote Link to comment https://forums.phpfreaks.com/topic/304278-issues-with-isset/#findComment-1548121 Share on other sites More sharing options...
Jacques1 Posted July 9, 2017 Share Posted July 9, 2017 But my problem is still persisting. Then you clearly haven't read the reply, Mr. Newbie. Quote Link to comment https://forums.phpfreaks.com/topic/304278-issues-with-isset/#findComment-1548122 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.