我在做PHP中的批量删除时,出现了问题?请高手帮忙 我用的是复选框,但是我提交过来的时候总是只得到一个值,请大家帮帮忙啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 复选框名字用数组来表示:<input type="checkbox" name="checkbox[]" value="">服务器端取得值为数组,就可以处理了. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><script language="javascript"> function selectAll() { for(var i=0;i<document.form1.del[].length;i++) { document.form1.del[][i].checked=false; } } function unSelect() { for(var i=0;i<document.form1.del[].length;i++) { if(document.form1.del[][i].checked) { document.form1.del[][i].checked=false; } else { document.form1.del[][i].checked=true; } } } </script> <body><form name="form1" method="post" action="delPost.php"> <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000"> <tr bgcolor="#FFFFFF"> <td width="96" height="25"><div align="center">用户名</div></td> <td width="136" height="25"><div align="center">密码</div></td> <td width="115"><div align="center">登陆时间</div></td> <td width="148"><div align="center"> <input name="delete" type="submit" id="delete" value="删除"> <input type="button" name="Submit" value="全选" onclick="selectAll();"> <input type="button" name="Submit2" value="反选" onclick="unSelect();"> </div></td> </tr> <?php require_once("mysql.php"); $sql="select * from admin"; $result=dbConn($sql); while ($array=mysql_fetch_array($result["rs"])){ ?> <tr bgcolor="#FFFFFF"> <td height="25"><div align="center"> <?=$array["a_zhanghao"]?> </div></td> <td height="25"><div align="center"> <?=$array["a_mima"]?> </div></td> <td><div align="center"> <?=$array["login_time"]?> </div></td> <td><div align="center"> <input name="del[]" type="checkbox" id="del[]" value="<?php echo $array["a_id"]?>"></div></td> </tr> <?php}?> </table></form></body></html>调用的地方缺少对象,是怎么会事啊? <form action="?" method="post"><input type="checkbox" name="checkbox[1]" value="a"><input type="checkbox" name="checkbox[2]" value="b"><input type="checkbox" name="checkbox[3]" value="c"><input type="submit"></form>程序<?if(!empty($_POST['checkbox']))foreach($_POST['checkbox'] as $k=>$v){ echo $k.'='.$v.'<br>';}?> 写法不对,请使用getElementsByName将javascript改成以下试试===============================<script language="javascript">var sid = document.getElementsByName('del[]');function selectAll(){ for(var i=0;i<sid.length;i++) { sid[i].checked=true; }}function unSelect(){ for(var i=0;i<sid.length;i++) { if(sid[i].checked) { sid[i].checked=false; } else { sid[i].checked=true; } }}</script> 为什么导出的.sql文件是空的呢? PHP中select的问题 如何实现PHP自动打印到网络打印机? 从mysql的DATE数据中提取时间 关于Smarty中Cache的一点疑问 PHP中在另一页面里怎样获取写往客户端的数据? 哪位大哥有PHP动态生成HTML的文章系统啊? 怎么取得本页的url?带参数的。 关于双语系统 函数几问 php 是什么?? 请教 简单运算为题
服务器端取得值为数组,就可以处理了.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="javascript">
function selectAll()
{
for(var i=0;i<document.form1.del[].length;i++)
{
document.form1.del[][i].checked=false;
}
}
function unSelect()
{
for(var i=0;i<document.form1.del[].length;i++)
{
if(document.form1.del[][i].checked)
{
document.form1.del[][i].checked=false;
}
else
{
document.form1.del[][i].checked=true;
}
}
}
</script>
<body>
<form name="form1" method="post" action="delPost.php">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr bgcolor="#FFFFFF">
<td width="96" height="25"><div align="center">用户名</div></td>
<td width="136" height="25"><div align="center">密码</div></td>
<td width="115"><div align="center">登陆时间</div></td>
<td width="148"><div align="center">
<input name="delete" type="submit" id="delete" value="删除">
<input type="button" name="Submit" value="全选" onclick="selectAll();">
<input type="button" name="Submit2" value="反选" onclick="unSelect();">
</div></td>
</tr>
<?php
require_once("mysql.php");
$sql="select * from admin";
$result=dbConn($sql);
while ($array=mysql_fetch_array($result["rs"])){
?>
<tr bgcolor="#FFFFFF">
<td height="25"><div align="center">
<?=$array["a_zhanghao"]?>
</div></td>
<td height="25"><div align="center">
<?=$array["a_mima"]?>
</div></td>
<td><div align="center">
<?=$array["login_time"]?>
</div></td>
<td><div align="center">
<input name="del[]" type="checkbox" id="del[]" value="<?php echo $array["a_id"]?>">
</div></td>
</tr>
<?php
}
?>
</table>
</form>
</body>
</html>
调用的地方缺少对象,是怎么会事啊?
<input type="checkbox" name="checkbox[1]" value="a">
<input type="checkbox" name="checkbox[2]" value="b">
<input type="checkbox" name="checkbox[3]" value="c">
<input type="submit">
</form>
程序
<?
if(!empty($_POST['checkbox']))
foreach($_POST['checkbox'] as $k=>$v){
echo $k.'='.$v.'<br>';
}
?>
将javascript改成以下试试
===============================
<script language="javascript">var sid = document.getElementsByName('del[]');function selectAll()
{ for(var i=0;i<sid.length;i++)
{
sid[i].checked=true;
}
}
function unSelect()
{
for(var i=0;i<sid.length;i++)
{
if(sid[i].checked)
{
sid[i].checked=false;
}
else
{
sid[i].checked=true;
}
}
}
</script>