ryanfilard Posted June 24, 2011 Share Posted June 24, 2011 I have to create a script that writes a user's email to a .txt file. I am using the code below and it does not seem to be working. <?PHP //Data to write $newsletterinfo = $REQUEST['email']; //Open the file directory $fdir = fopen('newsletter.txt'); //Write user email fwrite($fdir, $newsletterinfo); //Close the connection fclose($fdir); ?> Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/ Share on other sites More sharing options...
fugix Posted June 24, 2011 Share Posted June 24, 2011 Ou forgot an underscore in your request array. Try $newsletterinfo = $_REQUEST['email']; Also, I prefer using file_put_contents() Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/#findComment-1234368 Share on other sites More sharing options...
ryanfilard Posted June 24, 2011 Author Share Posted June 24, 2011 I changed it but it still does not work. I am doing something wrong? <?PHP //Data to write $newsletterinfo = $_REQUEST['email']; //Open the file directory $fdir = fopen('newsletter.txt'); //Write The Data fwrite($fdir, $newsletterinfo); //Close the connection fclose($fdir); ?> Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/#findComment-1234373 Share on other sites More sharing options...
fugix Posted June 24, 2011 Share Posted June 24, 2011 Just noticed, in your fopen() function, you dud not specify a mode in which to open the file. Change it to. $fdir = fopen('newsletter.txt','w'); Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/#findComment-1234390 Share on other sites More sharing options...
ryanfilard Posted June 24, 2011 Author Share Posted June 24, 2011 When I add the data how do I make it so it does not do this: [email protected]@[email protected]@[email protected]@email.com I want it to do this: [email protected] [email protected] [email protected] Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/#findComment-1234400 Share on other sites More sharing options...
fugix Posted June 24, 2011 Share Posted June 24, 2011 fwrite($fdir, $newsletterinfo . "\n"); Link to comment https://forums.phpfreaks.com/topic/240312-writing-a-string-to-a-file/#findComment-1234404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.