0

I am trying to send data from multiple Radio Button with name="answer<?php echo$data[id]?>". with this $_POST[answer[]]how I can save data ?

here is the code. thanks.

`<form method="post" action="proses.php">`<tbody>
<?php
$no=1;
$getdata = mysql_query("SELECT * FROM pertanyaan where kategori='pekerjaan' order by kategori desc");
        while($data=mysql_fetch_array($getdata)){
        ?>
<tr>
<td><?php echo $no ?></td>
<td><?php echo $data[pertanyaan]?></td>
<td><input type="radio" name="answer<?php echo $data[id] ?>" value="ss"></td>
<td><input type="radio" name="answer<?php echo $data[id] ?>" value="s"></td>
<td><input type="radio" name="answer<?php echo $data[id] ?>" value="b"></td>
<td><input type="radio" name="answer<?php echo $data[id] ?>" value="ts"></td>
<td><input type="radio" name="answer<?php echo $data[id] ?>" value="sts"></td>
</tr>
</form>
2
  • Can you please show output of var_dump($data) placed in the loop? Commented Jan 24, 2016 at 8:06
  • How do you submit the value .. i don't see the code,,, Commented Jan 24, 2016 at 8:15

2 Answers 2

1

You need to put square [] brackets in the name of radio battons.

<form method="post" action="proses.php">`<tbody>
<?php
$no=1;
$getdata = mysql_query("SELECT * FROM pertanyaan where kategori='pekerjaan' order by kategori desc");
    while($data=mysql_fetch_array($getdata)){
    ?>
<tr>
<td><?php echo $no ?></td>
<td><?php echo $data[pertanyaan]?></td>
<td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="ss"></td>
<td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="s"></td>
<td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="b"></td>
<td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="ts"></td>
<td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="sts"></td>
</tr>
</form>
Sign up to request clarification or add additional context in comments.

Comments

1
    <form method="post" action="proses.php">`<tbody>
    <?php
      $no=1;
      $getdata = mysql_query("SELECT * FROM pertanyaan where kategori='pekerjaan' order by kategori desc");
    while($data=mysql_fetch_array($getdata)){
    ?>
    <tr>
    <td><?php echo $no ?></td>
    <td><?php echo $data[pertanyaan]?></td>
    <td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="ss"></td>
   <td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="s"></td>
    <td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="b"></td>
    <td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="ts"></td>
    <td><input type="radio" name="answer[<?php echo $data[id] ?>]" value="sts"></td>
    </tr>
  </form>
   //process.php

    <?php 
     if(isset($_POST)) {

         $getRadio = $_POST['answer'];
            if(count($getRadio) > 0) {

             // While updating data

              foreach($getRadio as $key => $val) {

               $query = "Update  pertanyaan set kategori = $val  WHERE id = $key";
               mysql_query($query);
        }
       //Insert Data

       foreach($getRadio as $key => $val) {

         //$key Reference Id of Table
         // val get checked radio button value
         $query  = "insert into  TABLENAME values('NULL','$val','$key')"; 
         mysql_query($query);
      }
   }

 }?>

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.