duanna1407 2011-06-02 13:42
浏览 39
已采纳

php中的复选框 - 访问问题

i need to reproduce with the code below something like:

myformdata[languages1]
myformdata[languages2]
myformdata[languages3]

But with this code only reproduce myformdata[languages

    <?php
    $sql=mysql_query("select id_spoken_languages, language, path from spoken_languages");
    $i=0;
    while($row=mysql_fetch_array($sql)) {
    $id=$row['id_spoken_languages'];
    $data=$row['language'];
    $flag=$row['path'];
    echo nl2br ("<input type='checkbox' name='myformdata[languages'.$i++.']' value='$id' class='semLargura'>$data <img style='float:right; margin-top:5px; border:1px solid grey;' src='$flag'></img> 
");
    } 
    ?>

i already tried remove the increment and only access with $form_data_array["languages"][1] but in this case i get:


Notice: Uninitialized string offset: 1 in C:\Users\fel\VertrigoServ\www\login\validation2.php on line 9

but if i use `$form_data_array["languages"][0], no error is showed, seems like all checkbox have the index 0.

what is the best way to solve this problem?

  • 写回答

5条回答 默认 最新

  • dongwu5743 2011-06-02 13:48
    关注

    It looks like your output string may be incorrect. Try this one:

    echo nl2br ("<input type='checkbox' name='myformdata[languages".$i++."]' value='$id' class='semLargura'>$data <img style='float:right; margin-top:5px; border:1px solid grey;' src='$flag'></img> 
    ");
    

    I replaced the two instance of single quotes before and after the increment output with double quotes.

    Also note, there is no need to increment in PHP. All you need to add is two empty brackets [] and PHP will take care of the incrementing itself. So if you'd like to access the input with $_POST["languages"][1] you can do so by generating the following: name='languages[]'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波