duandai7601 2013-07-22 06:36
浏览 46

没有错误消息,但所有数据都无法导入

i want to import data from an excel file to phpmyadmin. i use library excel_reader2. when i click the import button there is no error message but all data fail to import.

here is my code

<?php

include "excel_reader2.php";

mysql_connect("dbHost", "dbUser", "dbPass");
mysql_select_db("dbname");

$data = new Spreadsheet_Excel_Reader($_FILES['userfile']['tmp_name']);

$baris = $data->rowcount($sheet_index=0);

$success = 0;
$fail = 0;

for ($i=2; $i<=$row; $i++)
{
$id = $id->val($i, 1);
$name = $name->val($i, 2);
$address = $address->val($i, 3);

$query = "INSERT INTO student VALUES ('$id', '$name', '$address')";
$result = mysql_query($query);

 if ($result) $success++;
 else $fail++;
}

echo "<h3>Import data finished</h3>";
echo "<p>Sum of success data : ".$success."<br>";
echo "Sum of fail data : ".$fail."</p>";
?>

and here is the result in my browser

Import data finished Sum of success data : 0 Sum of fail data : 100

Please, somebody help me.. Big thanks..

  • 写回答

1条回答 默认 最新

  • dqpciw9742 2013-07-22 06:58
    关注

    Maybe are you wrong when you get your datas from the excel. You may try that:

    $id = $data->val($i, 1);
    $name = $data->val($i, 2);
    $address = $data->val($i, 3);
    

    You start from i=2 and var baris is never used

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?