Line breaks in CSV export
Posted: Fri Jun 05, 2009 4:12 am
I have a form using fopen to make a csv and write to the file. I then later import the csv data into a MySQL database. It needs to be one row and since I set this up for fopen, I get a form export that randomly may have 2,3, or 4 lines instead of one. I'm guessing I need to trim and addslashes, but I attempted and failed. Here's my code: (oh, and the code below has added line returns in the $_POST section to make it easier on the screen, in the file, it's contiguous with commas separating values)
Here's my code:
Please help, I am hoping to stick to my deadline. This is happening with three forms.
Here's my code:
Code: Select all
//CSV DATA FROM FORM
$csv_output = '"'.$_POST['daily_aptDate'].'","'.$_POST['daily_timeIn'].'","'.$_POST['daily_timeInAMPM'].'",
"'.$_POST['daily_timeOut'].'","'.$_POST['daily_timeOutAMPM'].'","'.$_POST['daily_therapyType'].'",
"'.$_POST['daily_addNotes'].'"';
//CREATING CSV FILE AND APPENDING SINGLE ROW OF DATA
$handle = fopen($filename, 'w+');
fwrite($handle, $csv_output);
fclose($handle);
//REDIRECT TO SIGNATURE CAPTURE
$redirect = "sigcapture/daily/patient/capture.php";
header('Location: '.$redirect); die;