如何通过表格中的表单发送复选框

时间:2014-11-20 17:47:24

标签: php html forms xhtml html-table

我正在尝试制作一个购物篮页面,当勾选复选框时,会在购物篮页面上显示歌曲。我想我很接近我只需要最后一点。

数据库代码:

<?php
error_reporting(~E_ALL);
$conn = pg_connect("host=****** port=5432 
                    dbname=teaching user=csguest password=*******");

$res = pg_query ($conn, "SELECT artist, composer, genre, title, album, label, price,                description FROM music");
print "<table border='1'>";
print "<th></th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th>     <th>Label</th><th>Price</th><th>Description</th></tr>";
while($getColumn = pg_fetch_row($res))
{
    print "<tr>";
    print '<td><input type="checkbox" name="check_list[]"value="<?=$getColumn?>"</td>';
    for ($column = 0; $column < pg_num_fields($res); $column++)
    {
        print "<td>" . $getColumn[$column] . "</td>";
    }

    print "</tr>";
    foreach($_POST['check item'] as $item) {
    }
}
print '</table>'
?>

购物篮代码。

<?php
//print_r($_POST);
if(isset($_POST['submit'])){
    if(!empty($_POST['check_list'])) {
        // Counting number of checked checkboxes.
        $checked_count = count($_POST['check_list']);
        echo "You have selected following ".$checked_count." option(s): <br/>";
        // Loop to store and display values of individual checked checkbox.
        foreach($_POST['check_list'] as $selected) {
            echo "<p>".$selected ."</p>";
        }
        echo "<br/><b>Note :</b> <span>Similarily, You Can Also Perform CRUD Operations using These Selected    Values.</span>";
    }
    else{
        echo "<b>Please Select Atleast One Option.</b>";
    }
}
?>

0 个答案:

没有答案