Seperate CSV Header From Downloaded Data From Form Inputs
I have a form and a csv file. The inputs go into the csv quite well but for some odd reason, they display in one row... why is that? I want multiple rows per submission...
PHP:
<?php
$fn = $_POST['fn'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
//$emailMe = (isset($_POST['emailMe'])) ? $_POST['emailMe'] : 'No';
//validate
if(empty($fn) || empty($name) || empty($email) || empty($phone)){
$message = 'Fill in areas in red!';
$aClass = 'errorClass';}
$cvsData = $fn . "," . $name . "," . $email . "," . $phone . "," . $comments . "\n";
$fp = fopen("form_data.csv", "a" );
if($fp){
fwrite($fp, $cvsData);
fclose($fp);
}
?>
<M/>
Senior Poster
3,611 posts since Apr 2012
Reputation Points: 64
Solved Threads: 77
Skill Endorsements: 90
@<MICHAEL>
The inputs go into the csv quite well but for some odd reason, they display in one row... why is that? I want multiple rows per submission...
You need to used a foreach loop in order to get the rows
Base on code that you provided you can used this foreach example:
$cvsData =str_getcsv($fn,$name,$email,$phone,$comments."\n");
foreach($cvsData as &$Row) $Row = str_getcsv($Row, ";");
You can take it apart and figure it out.
LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45