--- nickvansmack9 <[EMAIL PROTECTED]> wrote: > My boss wants me to make a form and have the data go to his inbox and > also output to a > .csv file that is open-a-ble in Excel. > How do I set this up, i've tried to find a free script online but most > charge for it. > I need a quick tutorial on how its done if possible.
PHP includes built-in functions for opening, writing, and closing files on your server. You'll make special use of the fopen(), fwrite(), and fclose() functions for this process. The following is the basic example given at http://www.php.net/fwrite: -------------------------------------- <?php $filename = 'test.txt'; $somecontent = "Add this to the file\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"; } ?> ----------------------------------------------------------- It includes a generous amount of error-checking throughout the process, which is a good thing. One thing that it falls short on is that it writes the file in the same directory as the script. Probably not a good thing. You may want to add another variable to establish a different directory just for the csv files that are created. Notice the \n at the end of the line of $somecontent. This is the line-break character, which you will need if your csv file is to end up being more than one line. I don't know if each submission of the form needs to be a separate csv file or if you want to append each new submission to the same csv file (or theoretically, you could do both), so I left the "append" example from the site as is. The 'a' can be changed to several other things depending on what you want to do with the file. Now, this was kinda long just for a simple answer. But, the process is actually kinda complicated. If I had made my answer very indepth, this e-mail would be absolutely huge. If you need any part of this explained further, or something else added (for instance, attaching the csv file to an e-mail to your boss, etc.), post your question here or contact me off-list. Michael Roush [EMAIL PROTECTED] "The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect." -- Tim Berners-Lee, W3C Director and inventor of the World Wide Web __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com ------------------------ Yahoo! Groups Sponsor --------------------~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/CefplB/TM --------------------------------------------------------------------~-> The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning. Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php_mysql/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
