1
我想通過下面的代碼寫入數據到csv文件。追加問題而triying寫數據
的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,我剛剛創建了一個CSV文件名爲learning_goals.csv並創建了5個輸入"StudID", "StudName", "Com1", "Com2", "Com3", "Com4"
當我輸入我的數據和推它,它顯示
公告:未定義的屬性:在/opt/lampp/htdocs/data-export/CSV.php CSV :: $ csv_file上線178 無法附加TO CSV文件
有誰知道我該如何解決這個問題?