没有获得复选框的值

时间:2019-08-15 20:33:46

标签: php html mysql

我正在加载一个带有选中和未选中框的PHP页面。提交表单并使用library(shiny) ui <- fluidPage( tabsetPanel( tabPanel("one", textOutput('text')), tabPanel("two", uiOutput('select')) ) ) server <- function(input, output, session) { c <- reactive({ list("A", "B", "C") }) d <- reactiveValues(choice = "A") output$select <- renderUI({ selectInput( inputId = "choice", label = "Select input", choices = c(), selected = 1 ) }) observe({ req(input$choice) d$choice <- input$choice }) output$text <- renderText( d$choice ) } shinyApp(ui, server) 方法获取数组的值时,即使选中了复选框,$_POST数组中每个复选框的值为“ 0”。

我知道我的代码存在插值问题。请不要对此发表评论。

isReadOnly[]

这是<?php $departmentID = $_GET['departmentID']; $departID = $_POST['employees']; $isReadOnly = $_POST['isReadOnly']; if(isset($_POST['update'])) { for ($i=0; $i<sizeof ($departID);$i++) { $result3 = mysqli_query($db,"INSERT INTO userDepartment (userID, departmentID,isReadOnly) SELECT userID,'" . $departID[$i] . "'," . $isReadOnly[$i] . " FROM users where userID='$id'"); } } ?> SOME OTHER CODE... <?php $sql = "SELECT d.departmentID, d.departmentName, ud.departmentID, ud.isReadOnly FROM department d LEFT JOIN userDepartment ud ON ud.departmentID = d.departmentID AND ud.userID = '$id' ORDER BY d.departmentID ASC"; $result = mysqli_query($db,$sql); $c = 0; echo "<div class='manageUserTable'> <table><th colspan='2'>Budget</th><th>Is Read Only</th>\n"; while($row = mysqli_fetch_array($result)){ $departID = $row[2]; $checkedDep = ($row[0] == $departID) ? 'checked="checked"':''; $checkedreadOnly = ($row[3] == '1') ? 'checked="checked"':''; echo "<tr> <td class='check'><input type='checkbox' name='employees[$c]' value='".$row['0']. "' " . $checkedDep . "'></td> <td class='depName'>".$row['1']."</td> <td class='check'><input type='hidden' name='isReadOnly[$c]' value='0'><input type='checkbox' name='isReadOnly[$c]' value='".$row['3']. "' " . $checkedreadOnly . "'> </tr>"; $c++; } echo "</table></div>\n"; ?> 中的var_dump

$_POST

array(5) { ["username"]=> string(15) "bobby.zimmerman" ["employees"]=> array(1) { [0]=> string(1) "1" } ["isReadOnly"]=> array(29) { [0]=> string(1) "0" [1]=> string(1) "0" [2]=> string(1) "0" [3]=> string(1) "0" [4]=> string(1) "0" [5]=> string(1) "0" [6]=> string(1) "0" [7]=> string(1) "0" [8]=> string(1) "0" [9]=> string(1) "0" [10]=> string(1) "0" [11]=> string(1) "0" [12]=> string(1) "0" [13]=> string(1) "0" [14]=> string(1) "0" [15]=> string(1) "0" [16]=> string(1) "0" [17]=> string(1) "0" [18]=> string(1) "0" [19]=> string(1) "0" [20]=> string(1) "0" [21]=> string(1) "0" [22]=> string(1) "0" [23]=> string(1) "0" [24]=> string(1) "0" [25]=> string(1) "0" [26]=> string(1) "0" [27]=> string(1) "0" [28]=> string(1) "0" } ["id"]=> string(2) "82" ["update"]=> string(14) "Update Account" } 的索引0在该输出中应该为“ 1”。

1 个答案:

答案 0 :(得分:0)

在这一行:<input type='checkbox' name='isReadOnly[$c]' value='".$row['3']. "' " . $checkedreadOnly . "'>value='".$row['3']. "'应该是value='1'