Page 1 of 1

Appending to Text file with php

Posted: Sun Sep 05, 2004 1:27 pm
by kvigorous
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi all, 
I'm trying to make a simple database using a text file that gets its values from a form. I want to set up the script so that each item is separated by a comma. Then the data from each new submission from the form gets written to the next line. Here's what I have so far:

Code: Select all

<?php 
$fp = fopen("submission.txt","a"); 
$content = "Band Name:".$_POST["band_name"]." Contact:".$_POST["contact"]." Email:".$_POST["email"]." Home Phone:".$_POST["home_phone"]." Cell Phone:".$_POST["cell_phone"]." Contact:".$_POST["city"]." Contact:".$_POST["state"]." Contact:".$_POST["link"]." Contact:".$_POST["bio"]."\r\n"; 
fwrite($fp,$content); 
fclose($fp); 
?>
I know that this isn't right to separate the fields by commas, but I get this error when I submit from the form:

Code: Select all

Warning: fopen("submission.txt", "a") - Permission denied in /home/httpd/vhosts/arxposure.com/httpdocs/db/submission2.php on line 2 

Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/arxposure.com/httpdocs/db/submission2.php on line 5 

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/arxposure.com/httpdocs/db/submission2.php on line 6
By the way, I have set the permissions for the directory for full read/write. Thanks very much for the help, everyone.


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Sep 05, 2004 4:10 pm
by timvw
you need to make sure the file itself has write access for the user that runs the webserver... Usually this is done with chmod o+r /the/file (assuming www-data/nobody is not in the group)

Btw:
I don't see any comma's being output at all in your script?
And each line having redundant data as "Contact: ", "Email: ", etc doesn't seem very usefull either (Store the names of each columns once as the first row in your file fe.. this way even Excell can use them easily :) :)

it works now

Posted: Mon Sep 06, 2004 2:45 pm
by kvigorous
thanks. that did it.