Jump to content

Sending form data to csv file


Recommended Posts

Ok, I have tried using the code from this link http://answers.yahoo.com/question/index?qid=20100927173625AAmEmiW

 

<?php
// Get the name they entered in the form
// We'll be naming the file this
$file = $_POST['name'];
// Get the email from the form
$email = $_POST['email'];
// We want the file to be a text file right?
$ex = ".txt";
// Try to open a file named $file$ex (johndoe.txt for example)
// Because this file doesn't exist yet the server creates it
$write = fopen("$file$ex","w");
// Now open the file up again but this time save the email in it
fwrite($write,$email);
// MAKE SURE you close the file!!!
fclose($write);
// The folder that this script is in on the server is where the file we just made was saved
// We can 'rename' it to another folder
// The folder on the server we want to move it to 
$data = "../emails/";
// Now put it all together: This example goes out of the folder we're in and into the folder 'emails'
// The new 'name' would be this now (../emails/johndoe.txt): So now the file is moved to where we want for storage
rename ("$file","$data$file$ex");
// The script is done, send the user to another page (Just read the address below and you'll get it)
exit;
?>

 

 

unfortunately it doesn't do as i would like.  I'm not sure how to get it to save a new file based on a variable on the form page or from one of the fields in the form.  What i need is a way for a user to submit the form and it save the data into a uniquely named csv file.  I know the code given is for text files, not csv, but that was about all i could find.  If there is any help i would greatly appreciate it.

 

Link to comment
https://forums.phpfreaks.com/topic/235923-sending-form-data-to-csv-file/
Share on other sites

This is a forum for help with original code. If it's someone else's script, I suggest getting support from them.

 

The code posted above is very dangerous, and will allow someone to mess with files you might not want them to.

 

$_POST['name'] = '../../some/other/folder/file';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.