-1

i am trying to do within PHP page.I have form which contains radio button and i want to get their value and place in array. I dont know where i am doing wrong.

code:

   $example = array();
   $i=0;
    while($row = mysql_fetch_array($query) or die(mysql_error())){
        $a= $row['A'];
        echo '<form method="get" action="?page=".$next."">'; 
        while ($row=mysql_fetch_array($query))
        {

            echo '<div class="boxed" >';

            echo "\t".'<tr><th>'.
            $row['question']."<br>".
            '</th><th>'."<input type='radio' name= 't[]' value='{$row['A']}'>".$row['A']."<br>".
            '</th><th>'."<input type='radio' name='t[]' value='{$row['B']}'>".$row['B']."<br>".
            '</th><th>'."<input type='radio' name='t[]' value='{$row['C']}'>".$row['C']."<br>".
            '</th><th>'."<input type='radio' name='t[]' value='{$row['D']}'>".$row['D'].'</th>
            </tr>';
            echo '<input type="hidden" name="page" value="'.$next.'">';
            echo '<input type="submit" name="submit"/>';
            $i++;

            echo '</div>';


            echo '</div>';
    }
    echo '</form>';
    if (isset($_GET['submit'])) {
        $example[] = $_GET['t'];

        echo $example . 'chk';
    }


}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Malik
  • 193
  • 3
  • 12
  • you should be getting errors displayed or written to your php error log. Start your debugging be looking in the error log – RiggsFolly Jan 10 '16 at 11:18
  • Possible duplicate of [Html/PHP - Form - Input as array](http://stackoverflow.com/questions/20184670/html-php-form-input-as-array) – greenmarker Jan 10 '16 at 11:46
  • greenmaker i searched thats why i came here. Why did u anti vote? Shall i report against u? and it is still open in my browser. – Malik Jan 10 '16 at 16:40

1 Answers1

1

replace .$example=$_GET['t']; $example itself a be array. you can process it as you need

  if (isset($_GET['submit'])) {
    $example[] = $_GET['t'];

    echo $example . 'chk';
}

to

  if (isset($_GET['submit'])) {
      $example = $_GET['t'];

      for($i=0;$i<sizeof($example);$i++){
          echo $example[$i]."<br>";
      }

  }

or you can use foreach also

if (isset($_GET['submit'])) {
    $example = $_GET['t'];
    foreach ($example as $value) {
        echo "$value <br>";
    }
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Vigneswaran S
  • 2,039
  • 1
  • 20
  • 32