dongluobei9359 2018-01-31 09:34
浏览 57
已采纳

Php没有从表单接收数据

I have a excerpt of my form, as follows:

// If logged in shows this box (it's backed behind a include php file that makes the login check

<form action="./saveList.php" method="post" id="ListaComprasForm">
<div class="submitButtonEncap">
  <button type="submit" method="POST" name="submitButton" class="btn btn-primary roundedBorder" form="ListaComprasForm" value="submit">
      <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Save List
  </button>
</div>

<input type="text" id="Limpeza0" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_0" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza1" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_1" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza2" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_2" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza3" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_3" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza4" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_4" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza5" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_5" name="L_chckb_[]" value="check"/>

<input type="text" id="Limpeza6" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_6" name="L_chckb_[]" value="check"/>

</form>

This form, on submit, will submit to a DB wether or not checkboxes and TextBox fields have been filled or not. The checkboxes that have been checked or not, he'll submit them over as Y and N or nullo for the Textboxes respectively through some sorting code as follows:

if (isset($_POST['submitButton'])){

    $L_chck[] = array();
    $H_chck[] = array();
    $V_chck[] = array();
    $F_chck[] = array();
    $Cong_chck[] = array();
    $Cons_chck[] = array();
    $Outros_chck[] = array();

    $Outros = array();

    for ($counter = 0; $counter <= 6; $counter++){
        $L_chck[$counter] = (isset($_POST['L_checkb_'.$counter]) ? 'Y' : 'N');
        $H_chck[$counter] = (isset($_POST['H_checkb_'.$counter]) ? 'Y' : 'N');
        $V_chck[$counter] = (isset($_POST['V_chckb_'.$counter]) ? 'Y' : 'N');
        $F_chck[$counter] = (isset($_POST['F_chckb_'.$counter]) ? 'Y' : 'N');
        $Cong_chck[$counter] = (isset($_POST['Cong_chckb_'.$counter]) ? 'Y' : 'N');
        $Cons_chck[$counter] = (isset($_POST['Cons_chckb_'.$counter]) ? 'Y' : 'N');
        $Outros_chck[$counter] = (isset($_POST['Outros_chckb_'.$counter]) ? 'Y' : 'N');

    if (empty($_POST['Outros'.$counter])) {
            $Outros[$counter] = $_POST['Outros'.$counter] = 'nullo';
        } else {
        $Outros[$counter] = $_POST['Outros'.$counter];
        }

    }


for ($i=0; $i <= 4; $i++) { 
        /*if ((isset($_POST['Limpeza'.$i])) == false) {*/
        if (empty($_POST['Limpeza'.$i])) {
            $Limpeza[$i] = $_POST['Limpeza'.$i] = 'nullo';
        } else {
            $Limpeza[$i] = $_POST['Limpeza'.$i];
        }

        if (empty($_POST['Higiene'.$i])) {
            $Higiene[$i] = $_POST['Higiene'.$i] = 'nullo';
        } else {
            $Higiene[$i] = $_POST['Higiene'.$i];
        }

        if (empty($_POST['Vegetais'.$i])) {
            $Vegetais[$i] = $_POST['Vegetais'.$i] = 'nullo';
        } else {
            $Vegetais[$i] = $_POST['Vegetais'.$i];
        }

        if (empty($_POST['Fruta'.$i])) {
            $Fruta[$i] = $_POST['Fruta'.$i] = 'nullo';
        } else {
            $Fruta[$i] = $_POST['Fruta'.$i];
        }

        if (empty($_POST['Congelados'.$i])) {
            $Congelados[$i] = $_POST['Congelados'.$i] = 'nullo';
        } else {
            $Congelados[$i] = $_POST['Congelados'.$i];
        }

        if (empty($_POST['Conservas'.$i])) {
            $Conservas[$i] = $_POST['Conservas'.$i] = 'nullo';
        } else {
            $Conservas[$i] = $_POST['Conservas'.$i];
        }
    }

This data is then passed on as arguments to a function to be serialized and sent to DB fields, all of them varchar(255):

 savingListData($L_chck, $H_chck, $V_chck, $F_chck, $Cong_chck, $Cons_chck, $Outros_chck, $Limpeza, $Higiene, $Vegetais, $Fruta, $Congelados, $Conservas, $Outros);

So far, every piece of data, being it checked/filled or not, it transposes over to the DB as null. In the case of the checkboxes, N, and in the case of the Textboxes nullo.

I'm led to believe that something is wrong in the sorting but I'm puzzled and can't figure out why. Would really appreciate some help!!

EDIT: Added more of the form in a shortened manner. (It's a big form!)

  • 写回答

1条回答 默认 最新

  • doubi4814 2018-01-31 09:36
    关注

    I think you are trying to retrieving it using wrong name. Its L_chckb_[]

    <input type="checkbox" class="x" id="L_chck_0" name="L_chckb_[]" value="check"/>
    

    So you need to use the loop counter outside the name key like this:

    $L_chck[$counter] = (isset($_POST['L_chckb_'][$counter]) ? 'Y' : 'N');
    

    The problem is: the name attribute in the tag is L_chckb_ but you are trying to retrieve it by L_checkb_ so that is the issue.

    Because L_checkb_ is not set and so it is giving you N.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能