LoboTechServ Posted January 22, 2007 Share Posted January 22, 2007 Hi,I'm working on creating a script that will add email address from an html form into a text file and then allow the user to opt-out from another form. Not to familiar with working with text files in PHP. Any code examples would be helpfull, just point me to a good source, Thanks.Lobo Link to comment https://forums.phpfreaks.com/topic/35250-looking-for-code-examples-for-creating-subscriber-list-text-file/ Share on other sites More sharing options...
Lyleyboy Posted January 22, 2007 Share Posted January 22, 2007 Hi,I hope this helps. If not come back to me.Your form should look like this. Create a file called form.htm and put this in it.[code]<form action="form.php" method="post"><input type="text" name="name"> Your name<br><input type="text" name="email"> Your email<br><input type="checkbox" name="agree" checked>Yes! Put me on the list!<br><input type="submit">[/code]Your php page should look like this. Create a file called form.php and put this in it.[code]<?php//This section will add all the data to a text file called data.txt$file = 'data.txt';$fh = fopen($file, 'a') or die ('Cant open file'); //Use W to write to a new file A to appendfwrite($fh, "$name . $email . $agree") or die ('cant write to file');fclose($fh);//This section checks to see if the checkbox is ticked. If yes it will add the data to the second file, data2.txtif ($agree = "on") {$file = 'data2.txt';$fh = fopen($file, 'a') or die ('Cant open file'); //Use W to write to a new file A to appendfwrite($fh, "$name . $email . $agree") or die ('cant write to file');fclose($fh);} else {echo "The data was not added to the second file";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/35250-looking-for-code-examples-for-creating-subscriber-list-text-file/#findComment-166594 Share on other sites More sharing options...
LoboTechServ Posted January 23, 2007 Author Share Posted January 23, 2007 Thanks Lyleyboy, thats a great help, I'd love to see some more examples of this type of method... ;D Link to comment https://forums.phpfreaks.com/topic/35250-looking-for-code-examples-for-creating-subscriber-list-text-file/#findComment-166844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.