How to save several radiobuttons in MySql database?

0

Well, I need to save several groups of radiobuttons in the bank. Example:

<input type="radio" value="sim" name="grupo1">
<input type="radio" value="nao" name="grupo1">

<input type="radio" value="sim" name="grupo2">
<input type="radio" value="nao" name="grupo2">

<input type="radio" value="sim" name="grupo3">
<input type="radio" value="nao" name="grupo3">

There are 3 different groups, so I need to save the value of the chosen radio of each group in the bank.

Any help?

    
asked by anonymous 07.07.2016 / 15:37

2 answers

0

Thiago When you submit the form the value sent is only the one of the selected radio. This is because the radio group has the same name

You can test like this:

<form action="">
    <p>Pergunta 01</p>
    <label for="">Sim</label><input type="radio" value="sim" name="grupo1" required="">
    <label for="">Não</label><input type="radio" value="nao" name="grupo1" required="">
    <br><br>
    <p>Pergunta 02</p>
    <label for="">Sim</label><input type="radio" value="sim" name="grupo2" required="">
    <label for="">Não</label><input type="radio" value="nao" name="grupo2" required="">
    <br><br>
    <p>Pergunta 03</p>
    <label for="">Sim</label><input type="radio" value="sim" name="grupo3" required="">
    <label for="">Não</label><input type="radio" value="nao" name="grupo3" required="">

    <button>Enviar</button>
</form>
<?php 
    if ($_GET){
        echo "<p>Pergunta 01: </p> " . $_GET['grupo1'];
        echo "<p>Pergunta 02: </p> " . $_GET['grupo2'];
        echo "<p>Pergunta 03: </p> " . $_GET['grupo3'];
    }
?>
    
07.07.2016 / 16:03
0

Well, I do not know if I understood your question, but here it goes ..

For example, in the "value" of each "radio", put 0 or 1, considering 0 as not and 1 as yes. From there it is playing with these 2 values when the value is 1 marks when it is 0 ignores. For each group you use a unique ID genre.

mysql example:

***************
page_id ------ group_id ------ radio
***************
page1 --------- group1 --------- 0
page1 --------- group2 --------- 1
page2 --------- group3 --------- 0
page2 --------- group4 --------- 0

You can use the same table on several pages with several groups, when you select to load, you use "WHERE page_id == page you want".

    
07.07.2016 / 16:01