cmazur Posted November 8, 2006 Share Posted November 8, 2006 All I need to do is write the data entered on form of a webpage to a text file.I think I have the write syntax here, but the error part of my fopen() keeps executing.If I'm not mistaking, the second argument of my fopen(), 'a+', should create the fileif it doesn't already exist; which, in this case, the file doesn't existHere's the code, anything that you see goin' wrong here would be helpful.Thanks again...[code] <?php //Get form data values $title = $_POST["title"]; $composer = $_POST["composer"]; $performer = $_POST["performer"]; //Generate data to be written to the data file $data = "Song: " + $title + "\n" + "Composer: " + $composer + "\n" + "Artist/Group: " + $performer + "\n\n\n"; //Open a file and write the results to it $file = fopen("songs.dat", "a+") or die ("ERROR - songs.dat cannot be opened"); $bytes_written = fwrite($file, $data); fclose($file); ?> [/code] Quote Link to comment Share on other sites More sharing options...
RabPHP Posted November 8, 2006 Share Posted November 8, 2006 If your writing this from a webpage, make sure that the user Apache runs under has write permissions on songs.dat.In your shell, type $chown apache.apache songs.datAs for the code itself...Try..[code] <?php //Get form data values $title = "Test"; $composer = "Test2"; $performer = "Test3"; //Generate data to be written to the data file $data = "Song: " . $title . "\n" . "Composer: " . $composer ."\n" . "Artist/Group: " . $performer . "\n\n\n"; //Open a file and write the results to it $file = fopen("songs.dat", "a+") or die ("ERROR - songs.dat cannot be opened"); $bytes_written = fwrite($file, $data); fclose($file); ?>[/code]Substituting (.) for (+)Rab Quote Link to comment Share on other sites More sharing options...
cmazur Posted November 8, 2006 Author Share Posted November 8, 2006 Well, changing the + to . didn't do anything for me.As far as write access is concerned, that is probably the problem.I'm using a school server. Both the XHTML and PHP files are located in my directory to which I have access to write and read etc. Quote Link to comment Share on other sites More sharing options...
cmazur Posted November 8, 2006 Author Share Posted November 8, 2006 Any other help would be greatly appreciated.I'm really confused about what is goin' on here.Thanks again Quote Link to comment Share on other sites More sharing options...
cmazur Posted November 9, 2006 Author Share Posted November 9, 2006 Well, I guess this is my last effort to gather feedback.Does anyone have any ideas for me?Thanks again for all of the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.