Php 在triying写入数据时追加问题
我正试图通过下面的代码将数据写入csv文件 HtmlPhp 在triying写入数据时追加问题,php,forms,csv,file-writing,Php,Forms,Csv,File Writing,我正试图通过下面的代码将数据写入csv文件 Html 个人学习目标表 学生ID: 学生姓名: 评论1: 评论2: 评论3: 评论4: 我用kevin的类来写数据 这是我的php <?php require_once 'CSV.php'; $out_file = 'learning_goals.csv'; $csv = new CSV(); $headers = array ( // one row array ( // six columns 'St
个人学习目标表
学生ID:
学生姓名:
评论1:
评论2:
评论3:
评论4:
我用kevin的类来写数据
这是我的php
<?php
require_once 'CSV.php';
$out_file = 'learning_goals.csv';
$csv = new CSV();
$headers = array ( // one row
array ( // six columns
'StudID',
'StudName',
'Com1',
'Com2',
'Com3',
'Com4'
)
);
if ( !is_file( $out_file ) ) {
$csv->write_table( $headers, $out_file );
}
$data = array ( // one row
array ( // six columns
$_POST['StudID'],
$_POST['StudName'],
$_POST['Com1'],
$_POST['Com2'],
$_POST['Com3'],
$_POST['Com4']
)
);
$csv->append_table( $data );
// now you have a csv file in the same directory as this script
// you can read and edit it with excel, or also this class
// ... for demonstration purposes ...
// comment out the following for production
$table = $csv->parse_table();
print_r ( $table );
?>
我是csv新手,我刚刚创建了一个名为learning_goals.csv的csv文件,并创建了5个输入“StudID”、“StudName”、“Com1”、“Com2”、“Com3”、“Com4”
当我输入数据并按下时,它显示
注意:第178行/opt/lampp/htdocs/data export/CSV.php中未定义的属性:CSV::$CSV_文件
无法附加到CSV文件
有人知道我如何解决这个问题吗?您试图在构造函数或
load\u file(filename)
函数中不指定文件名的情况下附加到文件
请考虑改用write_table(data[,filename])
,如果您确实想追加,请使用load函数
<?php
require_once 'CSV.php';
$out_file = 'learning_goals.csv';
$csv = new CSV();
$headers = array ( // one row
array ( // six columns
'StudID',
'StudName',
'Com1',
'Com2',
'Com3',
'Com4'
)
);
if ( !is_file( $out_file ) ) {
$csv->write_table( $headers, $out_file );
}
$data = array ( // one row
array ( // six columns
$_POST['StudID'],
$_POST['StudName'],
$_POST['Com1'],
$_POST['Com2'],
$_POST['Com3'],
$_POST['Com4']
)
);
$csv->append_table( $data );
// now you have a csv file in the same directory as this script
// you can read and edit it with excel, or also this class
// ... for demonstration purposes ...
// comment out the following for production
$table = $csv->parse_table();
print_r ( $table );
?>