以下のコードを使用して、csv ファイルにデータを書き込もうとしています。
HTML
<html>
<body>
<form action="writeToExcel.php" method="post">
<center><h1>Personal Learning Goals Form</h1></center>
Student ID: <input type="text" name="StudID" /><br/>
Student Name: <input type="text" name="StudName" /><br/>
Comment 1: <input type="text" name="Com1" /><br/>
Comment 2: <input type="text" name="Com2" /><br/>
Comment 3: <input type="text" name="Com3" /><br/>
Comment 4: <input type="text" name="Com4" /><br/>
<input type="submit" value="Submit Form">
</form>
</body>
</html>
ケビンのクラスを使用してデータcsv.phpを書き込んでいます
これが私の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"
データを入力してプッシュすると、表示されます
Notice: 未定義のプロパティ: CSV::$csv_file in /opt/lampp/htdocs/data-export/CSV.php 行 178 CSV ファイルに追加できません
これを解決する方法を知っている人はいますか?