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

How to send checkbox through form in a table

提问人:harris 提问时间:11/21/2014 最后编辑:Brian Tompsett - 汤莱恩harris 更新时间:1/4/2017 访问量:155

问:

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

数据库代码:

<?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>";
    }
}
?>
php 表单 xhtml html-table

评论

1赞 Funk Forty Niner 11/21/2014
您是否在未发布的其他地方使用表单标签?另外,您是否设置了短开放标签?如果没有,请执行或更改为<?=<?php echo
0赞 harris 11/21/2014
在另一个div中,我正在使用表单,您知道如何解决我遇到的问题吗?代码示例会很好
0赞 Funk Forty Niner 11/21/2014
真的很难说,因为你没有显示完整的代码。根据您提出的另一个问题,您的提交按钮未命名,而此按钮使用的是条件语句。您的提交按钮确实命名了吗?即:,因为另一个只是.其他 stackoverflow.com/q/27000379if(isset($_POST['submit']))<input type="submit" name="submit" value="Submit"><input type="submit" value="Submit">
0赞 harris 11/21/2014
好的,到目前为止,我的代码将提交并发布复选框,但只显示值中的内容,但我需要的是它来显示行打印'<td><input type=“checkbox” name=“check_list[]”value=“<?=$res?>”</td>';
0赞 Funk Forty Niner 11/21/2014
更改为不起作用?可能就是这样。<?=$res?><?php echo $res; ?>

答: 暂无答案