我的FORM里有多选项,但提交后只能把最后一项插入数据库,请问各位高人这是
什么原因,如何解决;asp不会出现这种情况。
---------------------------------------------------------------
php要求同名表单元素用数组形式命名,并赋予value。否则他不能分解。
例:
1<input name="chk[]" type="checkbox" value="1"/>
1<input name="chk[]" type="checkbox" value="2"/>
1<input name="chk[]" type="checkbox" value="3"/>
提交后,用$_POST['chk']访问。数组中的元素为选中的复选框的值
---------------------------------------------------------------
if($submit)
{
foreach ($test as $val) {
echo $val."
1<br/>
";
}
}
$a=1;
$b=3;
?>
1<form action="<?=$PHP_SELF;?>" method="post">
2<input name="test[]" type="checkbox" value="1"/>
3<input name="test[]" type="checkbox" value="2"/>
4<input name="test[]" type="checkbox" value="3"/>
5<input name="submit" type="submit" value="submit"/>
6</form>
---------------------------------------------------------------
1<html>
2<head>
3<title>Untitled Document</title>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
5</head>
6<?
7if($check)
8{
9for($i=1;$i<=$countselected;$i++)
10{
11echo $checkboxid[$i]."<br>";
12}
13}
14?>
15<body bgcolor="#FFFFFF" text="#000000">
16<form action="" method="post" name="form1">
17<table align="center" border="0" cellpadding="0" cellspacing="0" width="80%">
18<?
19for($i=1;$i<=5;$i++)
20{
21?>
22<tr>
23<td>
24<input name="checkboxid[<?echo $i?>]" type="checkbox" value="选择[<?echo $i?>]"/>
25选择<?echo $i?>
26</td>
27</tr>
28<?
29}
30?>
31<input name="countselected" type="hidden" value="<?echo $i?>"/>
32<tr>
33<td>
34<input name="check" type="submit" value="Submit"/>
35</td>
36</tr>
37</table>
38</form>
39</body>
40</html>
全在这
---------------------------------------------------------------
多了$a, $b:(
if($submit)
{
foreach ($test as $val) {
echo $val."
1<br/>
";
}
}
?>
1<form action="<?=$PHP_SELF;?>" method="post">
2<input name="test[]" type="checkbox" value="1"/>
3<input name="test[]" type="checkbox" value="2"/>
4<input name="test[]" type="checkbox" value="3"/>
5<input name="submit" type="submit" value="submit"/>
6</form>
---------------------------------------------------------------
给你个例子.我试过了可以用
=========htm========
1<html>
2<head>
3<meta content="Microsoft FrontPage 5.0" name="GENERATOR"/>
4<meta content="FrontPage.Editor.Document" name="ProgId"/>
5<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
6<title>AB C</title>
7</head>
8<body>
9<form action="po.php" method="POST">
10<input name="chk[]" type="checkbox" value="1"/> A<input name="chk[]" type="checkbox" value="2"/>B
11<input name="chk[]" type="checkbox" value="3"/>C
12<input name="B1" type="submit" value="提交"/><input name="B2" type="reset" value="重置"/>
13
14</form></body>
15</html>
========htm=========
=======po.php=======
1
2extract($_GET);
3extract($_POST);
4echo $chk[0];
=====================
以上我只作了一个数组变量,要其它的可以用一个循环.$chk[0];修改0可得到其它的值.