请教一个一次性往数据库里添加多条记录的问题. addok.php里面开头你加一句print_R($_POST['addname']);你就可以看到,你传过来的数组的值了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $_POST['addname']是由你选择的名称组成的一维数组。 http://61.142.238.117/labor/workspace.html进入 工业园A区 - 村委会 - 俊景花园点击进入右边的三个小人的图标看看 ^_^是不是这种效果? <?require ("config.php");$names = $_POST['addname'];$conn=mysql_connect("本地数据库", "vcom", "vcom");mysql_select_db("test");foreach($names as $key=>$name){ $sql="select Filename from download where Filename='$name'"; if(mysql_num_rows(mysql_query($sql))>=1) unset($names[$key]);}$str = implode(",",$names);$conn=mysql_connect("远程数据库", "vcom", "vcom");mysql_select_db("test")$sql="select Id from download where Filename in ($str)";@$result=mysql_query($query)while($rs=mysql_fetch_object($result)){ $tmp[] = "('$rs->Url', '$rs->Filename', '$rs->Size', '$rs->$Status', '$rs->Finishsize', '$rs->Addedtime', '$rs->Endtime', '$rs->Starttime', '$rs->Actulstart', '$rs->Bitrate')";}$conn=mysql_connect("本地数据库", "vcom", "vcom");mysql_select_db("test")$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";$query .= implode(',', $tmp);@$result=mysql_query($query);if ($result) echo "<font color=red>恭喜您!成功添加记录!</font>";else echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";?> Parse error: parse error in /home/apache/focus/load/addok.php on line 156应该是这行出错$sql="select Id from download where Filename in ($str)"; $sql="select Id from download where Filename in ($str)";换成$sql="select * from download where Filename in ($str)";错误不是这的错,是有几个行的结尾我没写“;” <?require ("config.php");$names = $addname;require ("config.php");foreach($names as $key=>$name){ $sql="select Filename from download where Filename='$name'"; if(mysql_num_rows(mysql_query($sql))>=1) unset($names[$key]);}$str = "'".implode("','",$names)."'";if($str=="''") die('没有要新添加的条目');require ("config_2.php");$sql="select * from download where Filename in ($str)";@$result=mysql_query($sql);while($rs=mysql_fetch_object($result)){ $tmp[] = "('".$rs->Url."', '".$rs->Filename."', '".$rs->Size."', '".$rs->$Status."', '".$rs->Finishsize."', '".$rs->Addedtime."', '".$rs->Endtime."', '".$rs->Starttime."', '".$rs->Actulstart."', '".$rs->Bitrate."')";}require ("config.php");$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";if(!is_array($tmp)) die('远端数据库查找失败');$query .= implode(',', $tmp);@$result=mysql_query($query);if ($result) echo "<font color=red>恭喜您!成功添加记录!</font>";else echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";?> <?require ("config.php");$ids = $addname;require ("config.php");foreach($ids as $key=>$id){ $sql="select Id from download where Id=$id"; if(mysql_num_rows(mysql_query($sql))>=1) unset($ids[$key]);}$str = implode(",",$ids);if($str=="") die('没有要新添加的条目');require ("config_2.php");$sql="select * from download where Id in ($str)";@$result=mysql_query($sql);while($rs=mysql_fetch_object($result)){ $tmp[] = "('".$rs->Url."', '".$rs->Filename."', '".$rs->Size."', '".$rs->$Status."', '".$rs->Finishsize."', '".$rs->Addedtime."', '".$rs->Endtime."', '".$rs->Starttime."', '".$rs->Actulstart."', '".$rs->Bitrate."')";}require ("config.php");$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";if(!is_array($tmp)) die('远端数据库查找失败');$query .= implode(',', $tmp);@$result=mysql_query($query);if ($result) echo "<font color=red>恭喜您!成功添加记录!</font>";else echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";?> echo "<tr>"; echo "<td bgcolor='#ffffff' align='center'><input type='checkbox' name='addname[]' value='$rs->Id'></td>"; echo "<td bgcolor='#ffffff' align='center'>$rs->Filename</td>"; 改成echo "<tr>";$id = $rs->Id;$name = $rs->Filename;echo "<td bgcolor='#ffffff' align='center'><input type='checkbox' name='addname[]' value='$name'></td>";echo "<td bgcolor='#ffffff' align='center'>$name</td>"; 求教list列表中,相连两行的位置交换的mysql语句? PHP Security Scanner谁会使用 php做了无限循环,就是smarty 模板里在怎么调用。 php钢七连欢迎各位phper的加入 二维数组写入数据库的问题 再次iframe问题。。高分求指点 用php能不能得到访问者的ip地址 寻分页代码 php 兼职招聘!(上海) 请问这个错误信息是什么意思啊 这段上传的代码我实在是找不出来那里错了 想问个关于数据库结构优化的问题
点击进入右边的三个小人的图标
看看 ^_^是不是这种效果?
require ("config.php");
$names = $_POST['addname'];
$conn=mysql_connect("本地数据库", "vcom", "vcom");
mysql_select_db("test");
foreach($names as $key=>$name){
$sql="select Filename from download where Filename='$name'";
if(mysql_num_rows(mysql_query($sql))>=1)
unset($names[$key]);
}
$str = implode(",",$names);
$conn=mysql_connect("远程数据库", "vcom", "vcom");
mysql_select_db("test")
$sql="select Id from download where Filename in ($str)";
@$result=mysql_query($query)
while($rs=mysql_fetch_object($result)){
$tmp[] = "('$rs->Url', '$rs->Filename', '$rs->Size', '$rs->$Status', '$rs->Finishsize', '$rs->Addedtime', '$rs->Endtime', '$rs->Starttime', '$rs->Actulstart', '$rs->Bitrate')";
}
$conn=mysql_connect("本地数据库", "vcom", "vcom");
mysql_select_db("test")
$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";
$query .= implode(',', $tmp);
@$result=mysql_query($query);
if ($result)
echo "<font color=red>恭喜您!成功添加记录!</font>";
else
echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";
?>
$sql="select Id from download where Filename in ($str)";
换成$sql="select * from download where Filename in ($str)";错误不是这的错,是有几个行的结尾我没写“;”
require ("config.php");
$names = $addname;
require ("config.php");
foreach($names as $key=>$name){
$sql="select Filename from download where Filename='$name'";
if(mysql_num_rows(mysql_query($sql))>=1)
unset($names[$key]);
}
$str = "'".implode("','",$names)."'";
if($str=="''") die('没有要新添加的条目');require ("config_2.php");
$sql="select * from download where Filename in ($str)";
@$result=mysql_query($sql);
while($rs=mysql_fetch_object($result)){
$tmp[] = "('".$rs->Url."', '".$rs->Filename."', '".$rs->Size."', '".$rs->$Status."', '".$rs->Finishsize."', '".$rs->Addedtime."', '".$rs->Endtime."', '".$rs->Starttime."', '".$rs->Actulstart."', '".$rs->Bitrate."')";
}
require ("config.php");
$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";
if(!is_array($tmp)) die('远端数据库查找失败');
$query .= implode(',', $tmp);
@$result=mysql_query($query);
if ($result)
echo "<font color=red>恭喜您!成功添加记录!</font>";
else
echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";
?>
require ("config.php");
$ids = $addname;
require ("config.php");
foreach($ids as $key=>$id){
$sql="select Id from download where Id=$id";
if(mysql_num_rows(mysql_query($sql))>=1)
unset($ids[$key]);
}
$str = implode(",",$ids);
if($str=="") die('没有要新添加的条目');require ("config_2.php");
$sql="select * from download where Id in ($str)";
@$result=mysql_query($sql);
while($rs=mysql_fetch_object($result)){
$tmp[] = "('".$rs->Url."', '".$rs->Filename."', '".$rs->Size."', '".$rs->$Status."', '".$rs->Finishsize."', '".$rs->Addedtime."', '".$rs->Endtime."', '".$rs->Starttime."', '".$rs->Actulstart."', '".$rs->Bitrate."')";
}
require ("config.php");
$query = "insert into download (Url,Filename,Size,Status,Finishsize,Addedtime,Endtime,Starttime,Actulstart,Bitrate) values ";
if(!is_array($tmp)) die('远端数据库查找失败');
$query .= implode(',', $tmp);
@$result=mysql_query($query);
if ($result)
echo "<font color=red>恭喜您!成功添加记录!</font>";
else
echo "<meta http-equiv='refresh' content='2; url=add.php'><font color=red>添加失败!系统正在返回,请稍候...</font>";
?>
echo "<td bgcolor='#ffffff' align='center'><input type='checkbox' name='addname[]' value='$rs->Id'></td>";
echo "<td bgcolor='#ffffff' align='center'>$rs->Filename</td>";
改成echo "<tr>";
$id = $rs->Id;
$name = $rs->Filename;
echo "<td bgcolor='#ffffff' align='center'><input type='checkbox' name='addname[]' value='$name'></td>";
echo "<td bgcolor='#ffffff' align='center'>$name</td>";