0

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);
    }
?>
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@<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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.