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);
    }
?>
Member Avatar for LastMitch

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.