在PHP中动态创建复选框的名称

时间:2016-07-12 03:13:41

标签: php html

我刚刚编写了这段代码并动态分配了复选框的名称,并在按下删除按钮时删除了所选的复选框。但它不起作用。有人可以帮助我吗?

main.php



if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.dev")

    import django
    django.setup()

    # Override default port for `runserver` command
    from django.core.management.commands.runserver import Command as runserver
    runserver.default_port = "8080"

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)




delete.php



$snooverhtml = "select * from songs_list";
$query7 = mysqli_query($con, $snooverhtml);?>
<form method="post" action="delete.php">
<input id="deletebtn" type="submit" name="deletethis" value="Delete"/></br> 


<?php while($row = mysqli_fetch_assoc($query7)):?>
<input type="checkbox" name="<?php echo "cb".$row['sno.'];?>"/><?php echo $row['sno.']?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['songs_name']?></br>
<?php

endwhile;

?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您已使用PHP,因此$_POST['<?php echo"cb".$j;?>']不正确。那就是<?php echo"cb".$j;?>字面意思是$_POST的索引,它永远不会找到isset是假的。使用:

$_POST['cb'.$j']

或代码用法:

if (isset($_POST['cb'. $j])){

您还应该使用参数化查询。 http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

http://php.net/manual/en/security.database.sql-injection.php