2

hi i want to store value of each input text in different arrays how to do that for example store value of input text 1 in array 1 and value of input text 2 in array 2 and so on how to achieve that here is the code for print input text

for($r=1;$r<=10;$r++)
{
    echo"<form id='ponts'>
    <table>
    <tr>
   <td>Enter point number$r</td><td> <input type='text' id='pt$r' name='pt$r' pattern='[0-9.]+'/></td>

    </tr>
    </table>
    </form>";

}
4
  • 1
    name="pt[]" -> var_dump($_POST['pt']) Commented Dec 13, 2012 at 20:58
  • input value is a string, not an array. If you want to group inputs in arrays, your values should look like arr1[$r], arr2[$r] with depending on $r value; Commented Dec 13, 2012 at 20:58
  • u want one table or many tables ? Commented Dec 13, 2012 at 21:12
  • suppose that input text 1 has value =3 so i want to store that value in array1 and that input text 2 has value =20 so i want to store that value in array2 so how to do this automatically that's what i mean Commented Dec 13, 2012 at 21:41

2 Answers 2

2

I guess I didn't understand well, but the following script may be what you want.

<?php

$g=$_GET;

if( isset($g['pt']) ){
  // the form has been submitted.
  $ptValues=$g['pt'];

  print_r($ptValues);

}

echo "<form id='ponts'><table>";

for($r=1;$r<=10;$r++) 
{
       echo "<tr><td> Enter point number$r</td><td> <input type='text' id='pt$r' name='pt[]' pattern='[0-9.]+'/> </td></tr>";
}

echo "</table></form>";

?>

Maybe this:

<?php

$g=$_GET;

if( isset($g['pt0']) ){
  // the form has been submitted.
  $ptValues=array();

  for($i=0; isset($g['pt'.$i]); $i++ )
    $ptValues[]=$g['pt'.$i];  

  print_r($ptValues);

}

echo "<form id='ponts'><table>'";

for($r=1;$r<=10;$r++) 
{
       echo "<tr><td> Enter point number$r</td><td> <input type='text' id='pt$r' name='pt$r' pattern='[0-9.]+'/> </td></tr>";
}

echo "</table></form>";

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

Comments

0

maybe this is what u are looking for

echo"<table id='points'>";
   for($r=1;$r<=10;$r++)
     {
   echo"
 <tr>
 <td>Enter point number".$r."</td><td> <input type='text' id='pt".$r."' name='pt".$r."' pattern='[0-9.]+'/></td>

  </tr>
  ";
}
echo "</table>";

i dont know why you are using the form tags here .

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.