<?php
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) {
header("location: index.php");
exit();
}
include ("../config.php");
if(isset($_POST["Import"]))
{
echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
//$sql_data = "SELECT * FROM prod_list_1";
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
//print_r($emapData);
//exit();
$sql="INSERT INTO client (fid, fname, mname, lname, address, contact_num, category, bank, card_num, pin_num, salary_sched, salary, stat) VALUES
('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]','$emapData[7]','$emapData[8]','$emapData[9]','$emapData[10]','$emapData[11]','$emapData[12]')";
$res=$con->query($sql);
// $res=$con2->query($sql);
}
fclose($file);
echo 'CSV File has been successfully Imported';
}
else
echo 'Invalid File: Please Upload CSV File';
}
header("Location: ../clerk.php");
?>
我只在我的另一个php
文件中复制了这些文件并且它正在运行。但我不明白为什么在修改添加$emapData
有人可以帮帮我吗?
下面是第一个工作的样本。
<?php
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) {
header("location: index.php");
exit();
}
include ("../config.php");
if(isset($_POST["Import"]))
{
echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
//print_r($emapData);
//exit();
$sql = "INSERT INTO grades (stud_id, code, sub_desc, units, year, sem, prof, grade) VALUES
('$emapData[0]',
'$emapData[1]',
'$emapData[2]',
'$emapData[3]',
'$emapData[4]',
'$emapData[5]',
'$emapData[6]',
'$emapData[7]')";
$res=$con->query($sql);
// $res=$con2->query($sql);
}
fclose($file);
echo 'CSV File has been successfully Imported';
}
else
echo 'Invalid File: Please Upload CSV File';
}
header("Location: ../success.php");
?>