Stack Exchange
Submit of selected on checkbox items?
I print this form in a web page with php:
<?php
    include("connectDB.php");
    $mySQL=new MySQL();
    $queryResult=$mySQL->query("SELECT nombre, precio, id_producto FROM productos");
    echo "<form action= 'checkout.php'> method=''POST'";
    while($datos=$mySQL->fetch_array($queryResult))
    {   
        $n = 1;
        $nombre=$datos['nombre'];
        $id_producto=$datos['id_producto'];
        $precio=$datos['precio'];

        echo "<h1>$nombre</h1>";
        echo "<input type=\"checkbox\" name=\"$id_producto\" value=\"$nombre\"> Cantidad: <input type=\"number\" name=\"points\" min=\"1\" max=\"20\" step=\"1\" value=\"1\"><br>";
        echo "<h3>  Precio: $precio<br>";

    }

    echo "<br>";
    echo "<input type=\"submit\" class=\"button\" value=\"Comprar\">";
    echo "</form>";
?>

So it displays a list (which is a form within) of items which can be selected or checked, on submit, I want to do the $_POST[''] of only the checked items, how could I solve this?

I answered someone's post a while ago about how checkboxes work with forms, submitting and updating the DB.  Maybe it could help you?.  Checkboxes work off of their name and will be passed to post as an array of the values checked off... I think your html might have some errors in it, too.. echo "<form action= 'checkout.php'> method=''POST'"; doesn't look right.

When such checkboxes are printed, only those values which were checked are submitted.
If i understood you correctly you wanted to retrieve those that got posted, which you can follow with this simple method
    foreach($_POST as $post_key => $post_value){

        //Check that the particular input is int and numeric, since i believe the name is the id
        if(is_numeric($post_key) && is_int($post_key){
         //Here goes your code, $post_key is the id and $post_value is the $nombre
         //Although i admit that i have no idea what nombre is since it is in another language. Forgive me if id_producto is not numeric and unique.
        }

    }


Nombre means name :)

Nice. If you find the answer helpful, don't forget to accept it by clicking the green arrow to the right :)
