提交所选复选框项目


Submit of selected on checkbox items?

>我用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>";
?>

因此,它显示了可以选择或选中的项目列表(其中的表单),在提交时,我想只对选中的项目进行$_POST[''],我该如何解决这个问题?

打印此类复选框时,仅提交选中的值。

如果我理解正确,您想检索已发布的内容,您可以使用此简单方法进行操作

    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.
        }
    }