I'm trying to write data to a csv file, through the below code.
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>
I'm using kevin's class to write data csv.php
here's my 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 );
?>
I'm new to csv, I have just created a csv file named learning_goals.csv and created 5 inputs "StudID", "StudName", "Com1", "Com2", "Com3", "Com4"
When I input my data and push it, it shows
Notice: Undefined property: CSV::$csv_file in /opt/lampp/htdocs/data-export/CSV.php on line 178 UNABLE TO APPEND TO CSV FILE
Does anyone know how I can solve this?