dongsuishou8039 2013-06-21 14:59
浏览 7
已采纳

如何发布多个已应答复选框的值? - PHP

I have the following code below that retrieves one of four optional checkbox answers to one quesition.

In my database instead of reading the correpsonding value, it always posts 0for each time a box is ticked. I'm guessing this is the key. How is it possible to show the value here? I tried replacing key with value, but with no success.

-Here are my codes-

PHP:

foreach($_POST['Person'] as $key=>$Person) { 
    $_POST['Person'][$key] = intval($Person); 
}
$Person = implode(',', $_POST['Person']); 

HTML:

<ul class="ratings">
    <li><input type="checkbox" name="Person[1]" value="Excellent" /></li>
    <li><input type="checkbox" name="Person[2]" value="Good" /></li>
    <li><input type="checkbox" name="Person[3]" value="Satisfactory" /></li>
    <li><input type="checkbox" name="Person[4]" value="Poor" /></li>                    
</ul>   
  • 写回答

3条回答 默认 最新

  • dongxunhua2054 2013-06-21 15:05
    关注

    Try this:

    $Person = implode(',', array_keys($_POST['Person']));
    

    In the _POST['Person'] array, the keys are 1, 2, 3, 4, the values are Excellent, Good, Satisfactory, Poor. In your code, you were calling intval() on the values, which returns 0 for anything that isn't a number.

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类