HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Saving form data to a csv file
Post new topic   Reply to topic    HTML Help Forum -> HTML Form
View previous topic :: View next topic  
Author Message
marynorn



Joined: 15 Sep 2006
Posts: 4

PostPosted: Fri Sep 15, 2006 11:05 am     Saving form data to a csv file Reply with quote

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

PostPosted: Mon Sep 18, 2006 5:33 am     Reply with quote

Stick with PHP then. PHp can grab form data and write it to a text file.

http://www.w3schools.com/php/php_post.asp
http://www.w3schools.com/php/php_file.asp
http://uk.php.net/manual/en/function.fwrite.php
marynorn



Joined: 15 Sep 2006
Posts: 4

PostPosted: Mon Sep 18, 2006 4:32 pm     Reply with quote

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

PostPosted: Thu Sep 21, 2006 6:21 am     Reply with quote

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

PostPosted: Thu Sep 21, 2006 2:48 pm     Reply with quote

Nifty! Thanks Smile
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> HTML Form All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial