Not printing my checked checkboxes [duplicate]


Good night, I created 3 checkboxes and I made an array method so when I click on send it shows me the checkboxes selected with your value , but this is not happening, I'm testing so that I put in my original form that I'm going to need to list my selected checkboxes ...

Can anyone help me?


<title>Teste de checkbox</title>
    <h1>Teste de check</h1>

    <form method="post" action="form.php">

    <input type="checkbox" name="cor" value="azul">

    <input type="checkbox" name="cor" value="vermelho">

    <input type="checkbox" name="cor" value="amarelo">

    <input type="submit" name="olhar">




if(isset($_POST["cor"])) {

    for($i = 0; $i < count($_POST["cor"]); $i++) {

        echo "a cor ".$_POST["cor"] [$i]." foi selecionada";



Thank you ...

asked by anonymous 23.12.2016 / 03:39

1 answer


You just have to "vector" your inputs, as you used the same name, and then want to recover the value of all, it needs to be this way:

<form method="post" action="form.php">

<input type="checkbox" name="cor[]" value="azul">

<input type="checkbox" name="cor[]" value="vermelho">

<input type="checkbox" name="cor[]" value="amarelo">

<input type="submit" name="olhar">


I hope I have helped !!!

23.12.2016 / 03:46