Forum Moderators: coopster
"value1","value2","value3",...
I'm having difficulty figuring this out. I've tried several different methods, to no avail. Heres my code:
//saving record in a csv file
$file_name = "form.csv";
$first_row = "Process,VendorID,Type,Null1,FirstName,LastName,Null2\r\n";
$values = "Process,VendorID,Type,null,FirstName,LastName,null\r\n";
$is_first_row = false;
if(!file_exists($file_name))
{
$is_first_row = true ;
}
if (!$handle = fopen($file_name, 'a+')) {
die("Cannot open file ($file_name)");
exit;
}
if ($is_first_row)
{
if (fwrite($handle, $first_row ) === FALSE) {
die("Cannot write to file ($filename)");
exit;
}
}
if (fwrite($handle, $values) === FALSE) {
die("Cannot write to file ($filename)");
exit;
}
fclose($handle);
$values = "Process,VendorID,Type,null,FirstName,LastName,null\r\n"; With this:
$values = '"Process","VendorID","Type","null","FirstName","LastName","null"'."\r\n"; BTW you do not need to open the file with in "a+" mode as you are not reading from it. Use "a" mode instead.
e.g.:
---
$values = '"Process","VendorID","Type","null","$FirstName","$LastName","null"'."\r\n";
---
$FirstName and $LastName should read: "John","Doe", with values posted from the html form or selected from mysql. Instead, they just read "$FirstName","$LastName"