0

I have rows with a dynamic radio buttons for each. This is how it looks on the view part initial value of each row shows the current one saved on the database

enter image description here

I've been trying to make the update button work whenever a user wants to update one's status (per row), I'm not making any progress.

The code on the view part is as follows:

if ($row['STATUS'] == 'Active') {
                    echo "<td>
                            <input type='radio' value='Active' name='status' id='status' checked/><label>Active</label>
                            <input type='radio' value='Inactive' name='status' id='status' /><label>Inactive</label>    
                    ";
} else {
    echo "<td>
            <input type='radio' value='Active' name='status' id='status' /><label>Active</label>
            <input type='radio' value='Inactive' name='status' id='status' checked/><label>Inactive</label>";   
}

Please note that the code above is inside a foreach loop. I'm starting to think that this foreach loop has someething to do on why it only gets the last value returned by the result_array().

I even tried using JavaScript on the view part for the values of the radio buttons, but I can't seem to make it work as well.

Please help. Thanks.

Mad Coder
  • 117
  • 14
Neil
  • 65
  • 7
  • 1
    Possible duplicate of [POSTing Form Fields with same Name Attribute](https://stackoverflow.com/questions/2203430/posting-form-fields-with-same-name-attribute) – CBroe Apr 16 '18 at 06:30
  • `id='status'` is the culprit here. Use class instead – Praveen Kumar Apr 16 '18 at 06:31
  • Sorry about that. I already did something like this for the name attribute to avoid duplicates of the form fields `name='status".$row['ID']."`, I was able to get the values shown, however, I wanted the update button work when the user decides to change the value via the radio buttons – Neil Apr 16 '18 at 06:34

1 Answers1

2

If you want to get multiple values of formdata with same name then you have to change name as name[]

Try code as shown below

if ($row['STATUS'] == 'Active') {
    echo "<td>
<input type='radio' value='Active' name='status[]' class='status' checked/><label>Active</label>
<input type='radio' value='Inactive' name='status[]' class='status' /><label>Inactive</label>    
";
} else {
    echo "<td>
<input type='radio' value='Active' name='status[]' class='status' /><label>Active</label>
<input type='radio' value='Inactive' name='status[]' class='status' checked/><label>Inactive</label>";   
}
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40