Jump to content
Sign in to follow this  
ronniepeter

Issues with isset

Recommended Posts

<?php

if(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....

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

But my problem is still persisting.

 

Then you clearly haven't read the reply, Mr. Newbie.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • 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.