We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,608 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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);
    }
?>
2
Contributors
1
Reply
1 Hour
Discussion Span
6 Months Ago
Last Updated
2
Views
<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

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0573 seconds using 2.7MB