POST requesting randomized names












0














So i've run into an issue here.



I need to be able to select one of the two radio buttons that this code makes.



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='select' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='select' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


What is does is it gets every person from my database and creates 2 radio buttons for each of the people. but the problem i'm facing right now is is that i can only update one person. As in say 5 people appear in the table i can only select one of the radio buttons because they all have the same name.
Now i tried making the name of all the radio buttons the same name as the ID of the person but that doesn't work



I'm trying to make something like this:



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='".$ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


Which i can then call in my server.php



if (isset($_POST['ID'])) {
$value = $_POST['ID'];
$arr = explode(",", $value);
$query = "UPDATE docenten SET aanwezigheid = '" . $arr['0'] . "' WHERE ID = '" . $arr[1] . "'";
mysqli_query($db, $query);
} else {
array_push($errors, "Oeps er is iets fout gegaan");
}


Sorry if i'm not making any sense i'm really bad at asking these kinds of questions










share|improve this question






















  • Your $_POST['ID'] is not called ID on the name of the input radio
    – Cheshire
    Nov 19 '18 at 14:45






  • 1




    if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
    – ADyson
    Nov 19 '18 at 14:46












  • Remember, if any answer solves your question, mark it as the correct answer
    – Cheshire
    Nov 20 '18 at 12:17
















0














So i've run into an issue here.



I need to be able to select one of the two radio buttons that this code makes.



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='select' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='select' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


What is does is it gets every person from my database and creates 2 radio buttons for each of the people. but the problem i'm facing right now is is that i can only update one person. As in say 5 people appear in the table i can only select one of the radio buttons because they all have the same name.
Now i tried making the name of all the radio buttons the same name as the ID of the person but that doesn't work



I'm trying to make something like this:



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='".$ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


Which i can then call in my server.php



if (isset($_POST['ID'])) {
$value = $_POST['ID'];
$arr = explode(",", $value);
$query = "UPDATE docenten SET aanwezigheid = '" . $arr['0'] . "' WHERE ID = '" . $arr[1] . "'";
mysqli_query($db, $query);
} else {
array_push($errors, "Oeps er is iets fout gegaan");
}


Sorry if i'm not making any sense i'm really bad at asking these kinds of questions










share|improve this question






















  • Your $_POST['ID'] is not called ID on the name of the input radio
    – Cheshire
    Nov 19 '18 at 14:45






  • 1




    if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
    – ADyson
    Nov 19 '18 at 14:46












  • Remember, if any answer solves your question, mark it as the correct answer
    – Cheshire
    Nov 20 '18 at 12:17














0












0








0







So i've run into an issue here.



I need to be able to select one of the two radio buttons that this code makes.



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='select' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='select' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


What is does is it gets every person from my database and creates 2 radio buttons for each of the people. but the problem i'm facing right now is is that i can only update one person. As in say 5 people appear in the table i can only select one of the radio buttons because they all have the same name.
Now i tried making the name of all the radio buttons the same name as the ID of the person but that doesn't work



I'm trying to make something like this:



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='".$ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


Which i can then call in my server.php



if (isset($_POST['ID'])) {
$value = $_POST['ID'];
$arr = explode(",", $value);
$query = "UPDATE docenten SET aanwezigheid = '" . $arr['0'] . "' WHERE ID = '" . $arr[1] . "'";
mysqli_query($db, $query);
} else {
array_push($errors, "Oeps er is iets fout gegaan");
}


Sorry if i'm not making any sense i'm really bad at asking these kinds of questions










share|improve this question













So i've run into an issue here.



I need to be able to select one of the two radio buttons that this code makes.



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='select' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='select' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


What is does is it gets every person from my database and creates 2 radio buttons for each of the people. but the problem i'm facing right now is is that i can only update one person. As in say 5 people appear in the table i can only select one of the radio buttons because they all have the same name.
Now i tried making the name of all the radio buttons the same name as the ID of the person but that doesn't work



I'm trying to make something like this:



                        $data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='".$ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


Which i can then call in my server.php



if (isset($_POST['ID'])) {
$value = $_POST['ID'];
$arr = explode(",", $value);
$query = "UPDATE docenten SET aanwezigheid = '" . $arr['0'] . "' WHERE ID = '" . $arr[1] . "'";
mysqli_query($db, $query);
} else {
array_push($errors, "Oeps er is iets fout gegaan");
}


Sorry if i'm not making any sense i'm really bad at asking these kinds of questions







php sql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 14:43









Pulmenti

31




31












  • Your $_POST['ID'] is not called ID on the name of the input radio
    – Cheshire
    Nov 19 '18 at 14:45






  • 1




    if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
    – ADyson
    Nov 19 '18 at 14:46












  • Remember, if any answer solves your question, mark it as the correct answer
    – Cheshire
    Nov 20 '18 at 12:17


















  • Your $_POST['ID'] is not called ID on the name of the input radio
    – Cheshire
    Nov 19 '18 at 14:45






  • 1




    if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
    – ADyson
    Nov 19 '18 at 14:46












  • Remember, if any answer solves your question, mark it as the correct answer
    – Cheshire
    Nov 20 '18 at 12:17
















Your $_POST['ID'] is not called ID on the name of the input radio
– Cheshire
Nov 19 '18 at 14:45




Your $_POST['ID'] is not called ID on the name of the input radio
– Cheshire
Nov 19 '18 at 14:45




1




1




if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
– ADyson
Nov 19 '18 at 14:46






if you want to allow the selection of multiple people then you probably want a set of checkboxes instead of radio buttons. The whole point of radio buttons is to force the user to choose exactly one item from a set. Checkboxes allow 0 or more items to be selected, at the user's discretion. (Maybe I've misunderstood the situation but that's what it sounds like. I don't really know what the existing radio buttons are actually for, because their names are not in English)
– ADyson
Nov 19 '18 at 14:46














Remember, if any answer solves your question, mark it as the correct answer
– Cheshire
Nov 20 '18 at 12:17




Remember, if any answer solves your question, mark it as the correct answer
– Cheshire
Nov 20 '18 at 12:17












1 Answer
1






active

oldest

votes


















1














For what I can see, you are doing a loop for showing the list. You can use the ID as the name, but you will have to do the same loop while getting the POST.



$data = "SELECT * FROM docenten";
$var = mysqli_query($db, $data);
while ($row = mysqli_fetch_object($var)) {
echo "<tr>";
echo "<td>" . $row->ID . "</td>";
echo "<td>" . $row->Naam . "</td>";
echo "<td>" . $row->Afkorting . "</td>";
echo "<td>" . $row->aanwezigheid . "</td>";
echo "<td><input type='radio' name='".$row->ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
echo "</tr>";
}


Now you should do the same loop but with:



while ($row = mysqli_fetch_object($var)) {
if(isset($_POST[$row->ID])) {
// Do your query
}
}


That would check of the value for each entry is set or not.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377013%2fpost-requesting-randomized-names%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    For what I can see, you are doing a loop for showing the list. You can use the ID as the name, but you will have to do the same loop while getting the POST.



    $data = "SELECT * FROM docenten";
    $var = mysqli_query($db, $data);
    while ($row = mysqli_fetch_object($var)) {
    echo "<tr>";
    echo "<td>" . $row->ID . "</td>";
    echo "<td>" . $row->Naam . "</td>";
    echo "<td>" . $row->Afkorting . "</td>";
    echo "<td>" . $row->aanwezigheid . "</td>";
    echo "<td><input type='radio' name='".$row->ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
    echo "</tr>";
    }


    Now you should do the same loop but with:



    while ($row = mysqli_fetch_object($var)) {
    if(isset($_POST[$row->ID])) {
    // Do your query
    }
    }


    That would check of the value for each entry is set or not.






    share|improve this answer


























      1














      For what I can see, you are doing a loop for showing the list. You can use the ID as the name, but you will have to do the same loop while getting the POST.



      $data = "SELECT * FROM docenten";
      $var = mysqli_query($db, $data);
      while ($row = mysqli_fetch_object($var)) {
      echo "<tr>";
      echo "<td>" . $row->ID . "</td>";
      echo "<td>" . $row->Naam . "</td>";
      echo "<td>" . $row->Afkorting . "</td>";
      echo "<td>" . $row->aanwezigheid . "</td>";
      echo "<td><input type='radio' name='".$row->ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
      echo "</tr>";
      }


      Now you should do the same loop but with:



      while ($row = mysqli_fetch_object($var)) {
      if(isset($_POST[$row->ID])) {
      // Do your query
      }
      }


      That would check of the value for each entry is set or not.






      share|improve this answer
























        1












        1








        1






        For what I can see, you are doing a loop for showing the list. You can use the ID as the name, but you will have to do the same loop while getting the POST.



        $data = "SELECT * FROM docenten";
        $var = mysqli_query($db, $data);
        while ($row = mysqli_fetch_object($var)) {
        echo "<tr>";
        echo "<td>" . $row->ID . "</td>";
        echo "<td>" . $row->Naam . "</td>";
        echo "<td>" . $row->Afkorting . "</td>";
        echo "<td>" . $row->aanwezigheid . "</td>";
        echo "<td><input type='radio' name='".$row->ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
        echo "</tr>";
        }


        Now you should do the same loop but with:



        while ($row = mysqli_fetch_object($var)) {
        if(isset($_POST[$row->ID])) {
        // Do your query
        }
        }


        That would check of the value for each entry is set or not.






        share|improve this answer












        For what I can see, you are doing a loop for showing the list. You can use the ID as the name, but you will have to do the same loop while getting the POST.



        $data = "SELECT * FROM docenten";
        $var = mysqli_query($db, $data);
        while ($row = mysqli_fetch_object($var)) {
        echo "<tr>";
        echo "<td>" . $row->ID . "</td>";
        echo "<td>" . $row->Naam . "</td>";
        echo "<td>" . $row->Afkorting . "</td>";
        echo "<td>" . $row->aanwezigheid . "</td>";
        echo "<td><input type='radio' name='".$row->ID."' value='Afwezig,".$row->ID."'>Afwezig <input type='radio' name='".$ID."' value='Aanwezig,".$row->ID."'>Aanwezig";
        echo "</tr>";
        }


        Now you should do the same loop but with:



        while ($row = mysqli_fetch_object($var)) {
        if(isset($_POST[$row->ID])) {
        // Do your query
        }
        }


        That would check of the value for each entry is set or not.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 14:50









        Cheshire

        731619




        731619






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377013%2fpost-requesting-randomized-names%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith