将复选框插入PHP帖子数组

时间:2018-09-20 19:54:12

标签: php html mysql

很抱歉提出愚蠢的问题。我有一个包含多个动态生成复选框的表单,我想将其插入到post数组中,以将其移至下一页,然后对其进行操作。

表格:

<form action="campcreate.php" class="form" method="post">
<label for "campName">Campaign Name:</label>
<input type="text" id="campName" class="form-control" name="campName" placeholder="Campaign Name" required minlength="6" autofocus>
<label for "notes">Description:</label>
<textarea class="form-control" name="notes" rows="5" id="notes" placeholder="Add any useful notes or descriptions here"></textarea>
<h3>Select committee memmbers:</h3>
<p>Committee members can be changed as required,  all members selected as committee members will be able to view documents, meetings etc. connected to the campaign.</p>
<p>Assigning a committee member does <strong>not</strong> grant them any different admin privillages on the site.</p>
<?php getnames(); ?>

<div>
<button type="submit" class="btn btn-success float-right" id="create">Next</button>
<button type="button" class="btn btn-primary float-right" id="restart">Back</button>
</div> <!--Form Div--->
</form>

包含的功能:

function getnames(){
    global $conn;
$sqlga = "SELECT user_id, user_first, user_last FROM users WHERE (usr_acrive= 1) AND (perm!=0) ORDER BY user_last ASC";
$stmt = mysqli_stmt_init($conn);    
mysqli_stmt_prepare($stmt, $sqlga);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
    if ($row['user_id']!=$_SESSION['user_id']){
        $checked="";
    }else{
        $checked="checked disabled";
    }
    echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"> '.$row['user_first'] . ' '. $row['user_last'] .  '<br>';
   }
}

我想将这些复选框(正确显示)转发到下一页,但是我无法弄清楚如何在帖子中添加这些复选框,一个框将被自动选中(用户创建帖子),但是最多可以勾选100个其他框。

我尝试回显,但是我只能看到文本框。

欢迎任何指针。

1 个答案:

答案 0 :(得分:0)

帖子信息通过输入标签的名称发送

您正在循环并添加具有相同名称的输入:

echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"> '.$row['user_first'] . ' '. $row['user_last'] . '<br>';

您应该在回显时尝试创建一个唯一的名称,具体取决于您需要的操作...

例如(在foreach循环内):

$i++;
echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"'. $i. '> '.$row['user_first'] . ' '. $row['user_last'] . '<br>';