 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
marynorn
Joined: 15 Sep 2006 Posts: 4
|
Posted: Fri Sep 15, 2006 11:05 am Saving form data to a csv file |
|
|
|
I've been using formmail for a while to gather data on-line. However, I'm now receiving so much data that yanking it out of e-mails and putting it into Excel manually is a time consuming pain in the butt. I know it's possible to set up a cgi script that sends form data to a csv file that could be downloaded at the end of every week, but I have no idea how.
Any help on this subject would be appreciated.
(I have experience with HTML and CSS, have a vague idea what mySQL and PHP are, and am completely clueless about CGI and Perl) |
|
degsy

Joined: 23 Feb 2005 Posts: 2440 Location: North East, UK
|
|
marynorn
Joined: 15 Sep 2006 Posts: 4
|
Posted: Mon Sep 18, 2006 4:32 pm |
|
|
|
Thanks for the links, I get the feeling that should be a very simple thing to do, if only I knew the right questions to ask. That's the problem with being self-taught: you never know where the gaps in your knowledge are. |
|
degsy

Joined: 23 Feb 2005 Posts: 2440 Location: North East, UK
|
Posted: Thu Sep 21, 2006 6:21 am |
|
|
|
basic example from here
http://uk2.php.net/manual/en/function.fwrite.php
| Code: |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['Submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$err = '';
if(trim($name)==''){
$err .= '-Please enter a name<br>';
}
if(empty($email)){
$err .= '-Please enter an email address';
}
if(strlen($comment)==0){
$err .= '-Please enter a comment<br>';
}
if($err!=''){
echo $err;
}
else{
$filename = 'file.txt';
$somecontent = $name . ',' . $email . ',' . $comment . "\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
}
?>
<form name="form1" method="post" action="">
<p>Name:
<input name="name" type="text" id="name" value="Joe">
<br>
Email:
<input name="email" type="text" id="email" value="joeatemail.com">
<br>
Comment:</p>
<p>
<textarea name="comment">This is my comment</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
|
|
|
marynorn
Joined: 15 Sep 2006 Posts: 4
|
Posted: Thu Sep 21, 2006 2:48 pm |
|
|
|
Nifty! Thanks  |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|