Mohamed Abdelrahman
Mohamed Abdelrahman

Reputation: 81

different array for different input text

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>";

}

Upvotes: 2

Views: 93

Answers (2)

Muatik
Muatik

Reputation: 4171

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>";

?>

Upvotes: 2

echo_Me
echo_Me

Reputation: 37233

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 .

Upvotes: 0

Related Questions