1

I learn PHP and in one of examples I found a part of a code I don't understand.

....
if (array_key_exists('submited', $_POST)) {
        for ($i = 1; $i <= $_SESSION['counter']; $i++) {
            if (!empty($_POST['checkeditem' . $i]))
                if ($_POST['checkeditem' . $i] == 'on') {
                    $rezultat = mysqli_query($conn, "DELETE FROM gas WHERE id=" . $i);
                    echo "Checked items are deleted";
                }
        }
    } else {
....

In the code above I don't understand this code line:

$_POST['checkeditem' . $i] == 'on'

There is no attribute with the name='on' in entire code, so it is not related to any name attribute. What is value 'on' and is there other values like that one, that are related to $_POST? Could you suggest me what to google, to find more about this? Thank you.

1 Answers1

1

In the code above I don't understand this code line and here on seems checkbox is checked or not?

$_POST['checkeditem' . $i] == 'on'

will compare like

$_POST['checkeditem1'] == 'on'

$_POST['checkeditem2'] == 'on'

till the last iteration of the loop e.g 100th

$_POST['checkeditem100'] == 'on'
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103