How to get the checkbox values ​​that the user selected? value not an option, because it is an indicator of the correctness / incorrectness of the answer to the question. name is the same too.

  <p>1. Вопрос 1<br> <input type="checkbox" name="1" value="0"><i>1</i><br> <input type="checkbox" name="1" value="1"><i>2</i><br> <input type="checkbox" name="1" value="0"><i>3</i><br> <input type="checkbox" name="1" value="0"><i>4</i><br> <input type="checkbox" name="1" value="1"><i>5</i> </p> <p>2. Вопрос 2<br> <input type="checkbox" name="2" value="1"><i>1</i><br> <input type="checkbox" name="2" value="0"><i>2</i><br> <input type="checkbox" name="2" value="1"><i>3</i><br> <input type="checkbox" name="2" value="0"><i>4</i><br> <input type="checkbox" name="2" value="0"><i>5</i> </p> 

    1 answer 1

    1. For the name of all checkboxes, it is better to use an array.
    2. Not an option to post answers in an HTML form that the user can view! Answers must be stored in a PHP script, for example, in an array.

        <input type="checkbox" name="q1[]" value="1"><i>1</i><br> <input type="checkbox" name="q1[]" value="2"><i>2</i><br> <input type="checkbox" name="q1[]" value="3"><i>3</i><br> <input type="checkbox" name="q1[]" value="4"><i>4</i><br> <input type="checkbox" name="q1[]" value="5"><i>5</i> <input type="checkbox" name="q2[]" value="1"><i>1</i><br> <input type="checkbox" name="q2[]" value="2"><i>2</i><br> <input type="checkbox" name="q2[]" value="3"><i>3</i><br> <input type="checkbox" name="q2[]" value="4"><i>4</i><br> <input type="checkbox" name="q2[]" value="5"><i>5</i> 

    PHP code outline

     <?php $q[1]['true_answers'] = [2, 5]; // Правильные ответы на вопрос №1 // Обработка ответов на вопрос №1 if (is_array($_POST['q1'])) { $q1_request = $_POST['q1']; foreach ($q1_request AS $answer) { echo $answer."\n"; } }