我打印这个表单在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['']
,我该如何解决?< / p>
答案 0 :(得分:1)
打印此类复选框时,仅提交已检查的值。
如果我理解正确,你想要检索那些已经发布的内容,你可以用这个简单的方法来关注
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.
}
}