从复选框创建一个数组

时间:2017-05-08 20:41:23

标签: php

我尝试过多种方式使用此表单创建一个数组,但我无法找到任何有效的数据。我还需要在字符串中转换数组,以便我可以在数据库中添加它。这是代码 PHP

$Generea = isset($_POST['Genere']);
    $Genere = implode(";", $Generea);

HTML

<fieldset>
<legend>Genere*:</legend>
<input type = "checkbox" value="Action" Name="Genere[]"/>Action
<input type = "checkbox" value="Platform" Name="Genere[]"/>Platform
<input type = "checkbox" value="Shooter" Name="Genere[]"/>Shooter
<input type = "checkbox" value="Fighting" Name="Genere[]"/>Fighting
<input type = "checkbox" value="Beat 'em ups" Name="Genere[]"/>Beat 'em ups<BR>
<input type = "checkbox" value="Stealth" Name="Genere[]"/>Stealth
<input type = "checkbox" value="Survival" Name="Genere[]"/>Survival
<input type = "checkbox" value="Adventure" Name="Genere[]"/>Adventure
<input type = "checkbox" value="Avventura testuale" Name="Genere[]"/>Avventura testuale
<input type = "checkbox" value="Avventura grafica"/ Name="Genere[]"/>Avventura grafica<BR>
<input type = "checkbox" value="RPG" Name="Genere[]"/>RPG
<input type = "checkbox" value="MMO" Name="Genere[]"/>MMO
<input type = "checkbox" value="Strategy" Name="Genere[]"/>Strategy
<input type = "checkbox" value="Sandbox" Name="Genere[]"/>Sandbox
<input type = "checkbox" value="Simulation" Name="Genere[]"/>Simulation<BR>
<input type = "checkbox" value="Sport" Name="Genere[]"/>Sport
<input type = "checkbox" value="Racing" Name="Genere[]"/>Racing
<input type = "checkbox" value="Music" Name="Genere[]"/>Music
<input type = "checkbox" value="Party" Name="Genere[]"/>Party
<input type = "checkbox" value="Horror" Name="Genere[]"/>Horror
</fieldset>

作为Form方法,我使用POST

1 个答案:

答案 0 :(得分:0)

你应该破坏$_POST变量,而不是isset()(只是truefalse)的结果。

if (isset($_POST['Genere']) {
    $Genere = implode(';', $_POST['Genere']);
}