Php 是否提交选中的复选框项目?

Php 是否提交选中的复选框项目?,php,html,Php,Html,我使用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=$m

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


因此,它会显示一个列表(其中的一种形式),其中包含可以选择或选中的项目。提交时,我想只对选中的项目执行
$\u 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.
        }

    }

不久前,我回复了某人的帖子,内容是关于复选框如何处理表单、提交和更新数据库。复选框根据其
名称
工作,并将作为选中值的数组传递给post。。。我想你的html可能也有一些错误<代码>回显“方法=”POST'看起来不对。Nombre的意思是名称:)很好。如果您觉得答案有帮助,请不要忘记通过单击右侧的绿色箭头接受它:)