请大侠们帮帮忙啦这是我现在的代码
$db = create_peardb_handle();
$subHotel_temp=file("修改后活动分类汇总.csv");//连接EXCEL文件,格式为了.csv
for ($i=0;$i<count($subHotel_temp);$i++) 

$subHotel_string=explode(",",$subHotel_temp[$i]);//通过循环得到EXCEL文件中每行记录的值 
//将EXCEL文件中每行记录的值插入到数据库中
$subHotel_q=$db->query("insert into hotel_activities_2 (hotel_id,start_date,end_date,content,s_type) values('$subHotel_string[0]','$subHotel_string[1]','$subHotel_string[2]','$subHotel_string[3]','$subHotel_string[4]')");
$subHotel_t= $subHotel_q->fetchRow(DB_FETCHMODE_ASSOC);
unset($subHotel_string); 
}模板HTML:是<form  action="subHotel_import.php" method="post">
 <table width="400" border="0" cellspacing="1" cellpadding="1">
  <tr align="center"> 
   <td height="25" style="background-image:url({{$theme_v3}}/images/hotel_ad/left.jpg);" width="400" style="color:#FFFFFF ">文件导入</td>
  </tr>
  <tr align="center" valign="middle"> 
   <td align="center"  height="40"  bgcolor="#FFFFFF">选择导入文件:<input type="file" name="upload"  style="width:280px"></td>
  </tr>
  <tr align="center" valign="middle"> 
   <td style="background-image:url({{$theme_v3}}/images/hotel_ad/left.jpg);" height="24" width="400"> 
<div align="center">
       <input type="submit"  value="开始">
    </div>
   </td>
  </tr>
 </table>
 <input type="hidden" name="submit" value="submit">
</form>

解决方案 »

  1.   

    先设置为对号入座。然后把insert改为update
      

  2.   

    你数据库有可以精确定位的字段吗?还有excel中的数据确定数据库中都已存在了吗?如果不是的话,需要提供匹配的字段
      

  3.   

    使用replace into hotel_activities_2 (hotel_id,start_date,end_date,content,s_type) values()
    该语句针对为表中存在唯一所有的数据,如果插入的数据存在的话则改为更新,不存在进行插入操作!
      

  4.   


    excel表里并没有指示这条数据为哪个字段的,那该怎么办
      

  5.   

    出现这个错误是file(修改后活动分类汇总.csv) [function.file]: failed to open stream: No such file or directory in /var/www/2009/webroot/subject/hotel_admin/subHotel_import.php on line 7