2013-10-22 2 views
0

나는 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['']인데 어떻게 해결할 수 있습니까?

+1

이 간단한 방법으로 수행 할 수있는 게시있어 그들를 검색하고 싶어 DB. [어쩌면 그것은 당신을 도울 수 있습니까?] (http://stackoverflow.com/a/18641541/623952). 체크 박스는 자신의'name'에서 작동하고 ** 값 **의 배열로 포스트에 전달 될 것입니다. ** 여러분의 html에는 에러가있을 수도 있습니다.'echo "

method = ''POST ''; '가 올바르게 보이지 않습니다. –

답변

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

    } 
+0

옴므는 ** 이름 **을 의미합니다. – diegoaguilar

+0

니스. 대답이 도움이된다고 생각되면 오른쪽의 녹색 화살표를 클릭하여 동의하는 것을 잊지 마십시오. –

+0

감사합니다. 몇 시간 후에 확인해 보겠습니다. – diegoaguilar