快来啊我在php中发现的一个问题

来得查理 2008-04-07 04:41:35
是这样的,我在A页面做一个表单里面放了多个checkbox,name都是checkbox
当我要提交到B页面显示出来的时候却只显示了一个checkbox 里的值

<form id="form1" name="form1" method="get" action="cc.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><label>
<input type="checkbox" name="checkbox" id="checkbox" value="0" />
<input name="checkbox" type="checkbox" id="checkbox" value="1" />
<input name="checkbox" type="checkbox" id="checkbox" value="2" />
<input name="checkbox" type="checkbox" id="checkbox" value="3" />
<input name="checkbox" type="checkbox" id="checkbox" value="4" />
<input name="checkbox" type="checkbox" id="checkbox" value="5" />
<input name="checkbox" type="checkbox" id="checkbox" value="6" />
<input name="checkbox" type="checkbox" id="checkbox" value="8" />
<input name="checkbox" type="checkbox" id="checkbox" value="7" />
</label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
<?php
$aa = $_POST['checkbox'];
echo $aa;
?>
这是怎么回事,和ASP不一样啊!

有什么办法可以把所有的值都取到啊!!!!!
...全文
143 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
都是很好的建议! 值得学习
vitalgg 2008-04-13
  • 打赏
  • 举报
回复
怎样在 HTML 的 <form> 中建立数组?
要使你的 <form> 结果被当成 array 发送到 PHP 脚本,要对 <input>,<select> 或者 <textarea> 单元这样命名:

<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />


注意变量名后的方括号,这使其成为一个数组。可以通过给不同的单元分配相同的名字来把单元分组到不同的数组里:

<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyOtherArray[]" />
<input name="MyOtherArray[]" />


这将产生两个数组,MyArray 和 MyOtherArray,并发送给 PHP 脚本。还可以给数组分配指定的键名:

<input name="AnotherArray[]" />
<input name="AnotherArray[]" />
<input name="AnotherArray[email]" />
<input name="AnotherArray[phone]" />


AnotherArray 数组将包含键名 0,1,email 和 phone。


注意: 指定数组的键名是 HTML 的可选项。如果不指定键名,则数组被按照单元在表单中出现的顺序填充。第一个例子将包含键名 0,1,2 和 3。


vitalgg 2008-04-13
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 knowjava 的回复:]
学习.
[/Quote]

// KJ 水源的红人!竟然也在这里混! :) .
flyash1981 2008-04-12
  • 打赏
  • 举报
回复
<input name="checkbox <?PHP echo $i;?>"

中间空格去掉

checkbox<?PHP echo $i;?>
flyash1981 2008-04-12
  • 打赏
  • 举报
回复
<form id="form1" name="form1" method="POST" action="cc.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <label>
<?PHP for($i=0;$i<=8;$i++){?>
<input name="checkbox<?PHP echo $i;?>" type="checkbox" value="<?PHP echo $i;?>" " />
<?PHP }?>
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
<tr>
<td> <label>
<input type="submit" name="Submit" value="提交" />
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
</table>
</form>


cc.php

<?php
for($i=0;$i<=8;$i++){
echo $_POST['checkbox.$i']."<br>";
}
?>
xiayang618 2008-04-12
  • 打赏
  • 举报
回复
<form id="form1" name="form1" method="get" action="cc.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <label>
<input type="checkbox" name="checkbox[]" id="checkbox" value="0" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="1" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="2" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="3" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="4" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="5" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="6" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="8" />
<input name="checkbox[]" type="checkbox" id="checkbox" value="7" />
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
<tr>
<td> <label>
<input type="submit" name="Submit" value="提交" />
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
</table>
</form>

<?php
$aa = $_POST['checkbox'];
for($i=0;$i <count($aa);$i++)
{
echo $aa[$i]."<br>";
}
?>

这样就没有问题了的。
gcq911 2008-04-09
  • 打赏
  • 举报
回复
设置复选框的名字形式为name[]
ten789 2008-04-08
  • 打赏
  • 举报
回复
prin_r($_POST[a]);也会全部打印出来的
true_mariner 2008-04-08
  • 打赏
  • 举报
回复
1楼正解。
  • 打赏
  • 举报
回复
学习.
lovejuve 2008-04-07
  • 打赏
  • 举报
回复
确实是循环问题。
智商漫步 2008-04-07
  • 打赏
  • 举报
回复
<form id="form1" name="form1" method="get" action="cc.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <label>
<input type="checkbox" name="checkbox[]" id="checkbox" value="0" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="1" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="2" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="3" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="4" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="5" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="6" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="8" />
<input name="checkbox" type="checkbox[]" id="checkbox" value="7" />
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
<tr>
<td> <label>
<input type="submit" name="Submit" value="提交" />
</label> </td>
</tr>
<tr>
<td>  </td>
</tr>
</table>
</form>
<?php
$aa = $_POST['checkbox'];
echo $aa;
?>

成数组后输出来
来得查理 2008-04-07
  • 打赏
  • 举报
回复
<?php
$aa = $_POST['checkbox'];

for($i=0;$i<count($aa);$i++)

{
echo $aa[$i];
}
?>

这样运行就正常了`~~~谢谢!!!
来得查理 2008-04-07
  • 打赏
  • 举报
回复
如何提交到asp的页面上就可以全部显示出来,这是为什么????

<%
aa = Request.Form("Checkbox")

Response.Write(aa)
%>

打印结果 :0, 1, 2, 3, 4, 5, 6, 8, 7
来得查理 2008-04-07
  • 打赏
  • 举报
回复
试了一下还是不行啊~

只能取到一个值
还有什么别的办法吗???
来得查理 2008-04-07
  • 打赏
  • 举报
回复
好的,谢谢~

我试试看
Unending 2008-04-07
  • 打赏
  • 举报
回复
<form id="form1" name="form1" method="get" action="cc.php">
改成
<form id="form1" name="form1" method="POST" action="cc.php">

要不就$aa = $_GET['checkbox'];
来得查理 2008-04-07
  • 打赏
  • 举报
回复
可不可以写明白点啊,这样简单我不明白呢,我是新手~~
tony-杨 2008-04-07
  • 打赏
  • 举报
回复
id切记不要重复
加载更多回复(2)

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧