请各位大大帮我看看,以下代码哪里有问题,添加记录到数据库,数据库没任何反应,也没报错
<?php$uploaddir = '/var/www/html/firerp/upload';$uploadfile = $uploaddir .'/'. basename($_FILES['userfile']['name']);
$filepath=$_FILES['userfile']['name'];echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {    echo "File is valid, and was successfully uploaded.\n";
  $db_host="localhost";//服务器  $db_user="root";    //用户名  $db_psw="65555055";    //密码  $db_name="firerp";//数据库名  
 
 
$conn = mysql_connect($db_host,$db_user,$db_psw) or die("链接错啦");  mysql_select_db($db_name,$conn) or die("链接又错啦");  mysql_query("set names utf-8");  
$line = 0;
$file = fopen('upload/'.$filepath,"r"); 
$strSql="SELECT MAX(order_no) FROM `0_sales_orders`";  //查询order_no字段最大值
$query = mysql_query($strSql,$conn); 
$resulta= mysql_fetch_row($query);
$maxid=$resulta[0];$strSqld="SELECT MAX(id) FROM `0_sales_orders_details`";  //查询id字段最大值
$queryd = mysql_query($strSqld,$conn); 
$resultad= mysql_fetch_row($queryd);
$maxidd=$resultad[0];$strSqla="SELECT MAX(id) FROM `0_audit_trail`";  //查询id字段最大值
$querya = mysql_query($strSqla,$conn); 
$resultaa= mysql_fetch_row($querya);
$maxida=$resultaa[0];$strSqlr="SELECT MAX(id) FROM `0_refs`";  //查询id字段最大值
$queryr = mysql_query($strSqlr,$conn); 
$resultar= mysql_fetch_row($queryr);
$maxidr=$resultar[0];while ($result = fgetcsv($file)) {    
  
    //每次读取CSV里面的一行内容   

if ($line <> 0)
   {

$maxid++;
$maxidd++;
$maxida++;
$maxidr++;
 //以下为0_sales_orders表内容 
$b1=$result[17];
  $b2=$result[18];
 $b3=$result[19];
  $b4=$result[20];
  $b5=$result[21];
  $b6=$result[22];
  $dead="$b6,$b1,$b2,$b3,$b4,$b5";
  $ttype=30;
  $vers=0;
  $ty=0;
  $deno=2;
 $brco=2;
  $cure=$result[0];
 $orda=date("Y-m-d");
  $orty=1;
  $shvi=1;
  $coph=$result[24];
  $deto=$result[16];
  $frco=0;
  $frst="DEF";
  $deda=date("Y-m-d",strtotime("+1 day"));
  $pate=4;
  $tota=$result[11];
  
  //以下为0_sales_orders_details表内容 
 $stco=$result[7];
  $desc=$result[8];
  $qtse=1;
 $quan=$result[9];
  $dipe=0;
  //以下为0_audit_tril表内容
  $use=1;
  $stam=date("Y-m-d H:i:s");
  $fiye=5;
  $glse=0;
  
  
 echo "$maxid,$ttype,$vers,$ty,$deno,$brco,$maxid,$cure,$orda,$orty";
 echo "<br/>";
 echo "$maxidd,$maxid,$ttype,$stco,$desc,$qtse,$tota,$quan,$dipe";
 echo "<br/>";
 echo "<br/>";
 
 
 
$sql="INSERT INTO `firerp`.`0_sales_orders` (`order_no`, `trans_type`, `version`, `type`, `debtor_no`, `branch_code`, `reference`, `customer_ref`, `ord_date`, `order_type`, `ship_via`, `deliery_address`, `contact_phone`, `deliver_to`, `freight_cost`, `from_stk_loc`, `delivery_date`, `payment_terms`, `total`) VALUES ('$maxid','$ttype','$vers','$ty','$deno','$brco','$maxid','$cure','$orda','$orty','$shvi','$dead','$coph','$deto','$frco','$frst','$deda','$pate','$tota')";
  mysql_query($sql);
  
 
  $sqld="INSERT INTO `firerp`.`0_sales_orders_details` (`id`, `order_no`, `trans_type`, `stk_code`, `description`, `qty_sent`, `unit_price`, `quantity`, `discount_percent`) VALUES ('$maxidd','$maxid','$ttype','$stco','$desc','$qtse','$tota','$quan','$dipe')";
  mysql_query($sqld);  
 
  $sqla="INSERT INTO `firerp`.`0_audit_trail` (`id`, `type`, `trans_no`, `user`, `stamp`, `fiscal_year`, `gl_date`, `gl_seq`) VALUES ('$maxida','$ttype','$maxid','$use','$stam','$fiye','$orda','$glse')";
  mysql_query($sqla);  
 
 $sqlr="INSERT INTO `firerp`.`0_refs` (`id`, `type`, `reference`) VALUES ('$maxidr','$ttype','$maxid')";
  mysql_query($sqlr);   
 } 
  $line++;
   //此为一个数组,要获得每一个数据,访问数组下标即可   
   }  fclose($file);  
echo "导入成功";


} else {
    echo "Possible file upload attack!\n";

}echo 'Here is some more debugging info:';
echo "</br>";print_r($_FILES['userfile']['name']);print "</pre>";?> 

解决方案 »

  1.   

    楼上大大,批评的对,不过我刚学PHP,很多还不是很明白,请见谅。
    我测试过应该是这段代码的问题,三个字段的表就能添加上去,这个表字段多,不知道是不是添加的内容不符合字段类型的要求$sql="INSERT INTO `firerp`.`0_sales_orders` (`order_no`, `trans_type`, `version`, `type`, `debtor_no`, `branch_code`, `reference`, `customer_ref`, 'comments',`ord_date`, `order_type`, `ship_via`, `deliery_address`, `contact_phone`,'contact_email', `deliver_to`, `freight_cost`, `from_stk_loc`, `delivery_date`, `payment_terms`, `total`) VALUES ('$maxid','$ttype','$vers','$ty','$deno','$brco','$maxid','$cure',NULL,'$orda','$orty','$shvi','$dead','$coph',NULL,'$deto','$frco','$frst','$deda','$pate','$tota')";
     
      

  2.   

    太多了,检查一下sql函数的返回值,多打点日志出来看看。
      

  3.   

    把这条sql语句,放到phpMyadmin或者其他mysql管理工具里,看能不能执行,哪里报错,就知道了。
      

  4.   

    谢谢楼上各位大大,我已经解决了,我直接从phpmyadmin里面复制出来,再改一下就行了,有个问题想问一下山本尚希
    川口啓太
    潮 圭二郎
    竹中 健人
    神田一生
    劉人杰
    手塚雄介
    山田 霜这些名字是我从日本网站上导出CSV文件里面的内容,这些名字写入到数据库都是空的,请问怎么解决,应该是编码的问题吧???
      

  5.   

    先确认一下CSV文件编码,之后再考虑转向你的数据库编码。