2

I want to retrieve the data from a textbox which I created. Please take look at my code and help me.

<?php
if(isset($_GET['ok']))
{
$a=1;
$n=$_GET['n'];
for($i=0;$i<$n;$i++){
    echo '<form action="exa.php" method="get">';
echo '<input type="text" name="kal'.$a.'"/> <br/>'; 
echo '</form>';
$a++;} $a=1;
for($i=0;$i<$n;$i++)
{
    $txtnm="kal".$a;
    $kal=$_GET['$txtnm'];
    echo $kal;  
    $a++;
}
}
?>

<html>
<body>
<form action="exa.php" method="get">
<input type="text" name="n"/><br/>
<input type="submit" value="OK" name="ok"/>
</form>
</body>
</html>

Here I am getting an error saying 'undefined index $txtnm'

4
  • 7
    PHP without whitespace is torture. Commented May 27, 2013 at 9:26
  • 1
    $kal=$_GET['$txtnm']; - Remove the quotation marks. Commented May 27, 2013 at 9:27
  • That is actually a notice..Ignore that. Commented May 27, 2013 at 9:27
  • All things are on the same page, so you will get that warning. Use it like if(isset($_GET[$txtnm])) { $kal = $_GET[$txtnm]; echo $kal }. You should first check if there is $_GET[$txtnm] element or not Commented May 27, 2013 at 9:37

3 Answers 3

1

here i am getting error that undefined index $txtnm ...

$kal=$_GET[$txtnm];

remove the single quotes, you are treating it as constant if you put those single quotes

Sign up to request clarification or add additional context in comments.

Comments

0

Try to do like this

echo 'Input '.$a.'<input type="text" name="kal[]"/> <br/>'; 

and after submitting form the kal array like

print_r($_REQUEST['kal']);

And why you are using get method,without specific need dont use get method while submitting the textarea data,because some of special characters causes your redirect

Comments

0

Remove single quote from $kal=$_GET['$txtnm'] . It should be

   $kal=$_GET[$txtnm];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.