juapo2 Posted December 23, 2007 Share Posted December 23, 2007 Hi, I have various very good scripts but i need help coding something some people may say is easy... I need a form, where my users add their e-mail adress to receive newsletter, i just need them to write their e-mail adress, and make the e-mail adress go into a .txt file, something like emails.txt I dont need script to send the newslettter or to unsubcribe them, just that their email adress goes into the .txt file, I would appreciate if you could help, Thany YOU. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/ Share on other sites More sharing options...
corbin Posted December 23, 2007 Share Posted December 23, 2007 No offense.... But that's extremely simple, and it sounds like you want someone to do it for you, which this board is not for (well, a section of it is, but....). http://www.tizag.com/phpT/files.php http://php.net/fopen http://php.net/fwrite http://www.google.com/search?hl=en&q=php+file+writing Try writing something, and then we can try to help ;p. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422000 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Ive never said it wasnt easy man, but thank you for the links Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422074 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 Ive never said it wasnt easy man, but thank you for the links than why are you asking for help? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422084 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Because for experts is very easy, but im not an expert..so i need help Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422091 Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 So, having looked at the links provided, were you able to come up with some code? Are you still stuck? Post what you have. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422093 Share on other sites More sharing options...
ohdang888 Posted December 24, 2007 Share Posted December 24, 2007 what corbin is trying to say is that we all have jobs and lives. we are not gonna sit here and write code for others. (if you want that, hire a web developer) You can write code, see if it works, if it doesn't, then post it here and we'll tell you whats wrong with it. but we can tell you HOW do to it... specify a file open it add text to it save it close it thats the general guideline of it. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422098 Share on other sites More sharing options...
ohdang888 Posted December 24, 2007 Share Posted December 24, 2007 oh and you'll also need to use HTML form with it. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422101 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 I got the form here is it, the HTML form: <h1>NewsLetter Subscribers</h1> <form action="subscribe.html" method="post" name="form"> Name: <input name="mailing_list_name" type="text" size="40"><br><br> Email: <input name="mailing_list_email" type="text" size="40"> <br><br> <input name="submit" type="submit" value="Submit"> <input name="reset" type="reset" value="Reset"> </form> Then this is my PHP code to add the e-mail to the list: <?php //Add item to list if(isset($_POST['submit']) && $_POST['mailing_list_name'] != "" && $_POST['mailing_list_email'] != "") { $file_ptr = fopen("list.txt", "a+") or die("Couldn't create new file"); fwrite($file_ptr, $_POST['mailing_list_name'] . "\r\n"); fwrite($file_ptr, $_POST['mailing_list_email'] . "\r\n\r\n"); fclose($file_ptr); } ?> And in my web server, i have a lists.txt file chmod to 777 Then i call the subscribe.html by doing this: http://mydomain.com/subscribe.html then, i add my name and email and i click submit, the same page appears and the lists.txt is still empty, now is there any1 that could help me? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422267 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 rename subscribe.html to subscribe.php because a file without a php extension will not run a php code.... also, be sure that you take your php code off the commented line so that it runs the code instead of treating it as a comment Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422268 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 I didnt understand the last part, can you explain it again? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422295 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 this should be the code on subscribe.php <?php //Add item to list if(isset($_POST['submit']) && $_POST['mailing_list_name'] != "" && $_POST['mailing_list_email'] != "") { $file_ptr = fopen("list.txt", "a+") or die("Couldn't create new file"); fwrite($file_ptr, $_POST['mailing_list_name'] . "\r\n"); fwrite($file_ptr, $_POST['mailing_list_email'] . "\r\n\r\n"); fclose($file_ptr); } ?> see the difference? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422297 Share on other sites More sharing options...
ohdang888 Posted December 24, 2007 Share Posted December 24, 2007 hey jaupo2... i have the same exact function in php. visitors enter an e-mail and it gets stored in a text file... but i have a suggestion for you... (heres my code...) <?php if (!isset($_POST['submit'])) {?> <form method="post"> E-Mail:<input type="text" size="15" maxlength="30" name="email"/> <br/> <input type="submit" name="submit" value="Submit"/> <form> <?php } else { $email = $_POST["email"]; $emailfile = "../emaillist.txt"; $FH = fopen($emailfile, 'a') or die("can't open file"); fwrite($FH,$email . ','); //LOOK AT THIS PART fclose($FH); } ?> look at the part that the comment tells you too.... see the ',' in "fwrite($FH,$email . ','); ", this tells the script to write a comma after the name, this will make your life a whole lot easier, all you have to do is copy and paste the e-mails, rather tahn seperating it youself. also, unless you have a realy good reason to want to know their names, it unneccesary also, put the if(isset($_POST['submit']) before your html text fields, if they have already submitted, it will not show the fields. but one question.. what does "\r\n\r\n"); do? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422419 Share on other sites More sharing options...
Grant Holmes Posted December 24, 2007 Share Posted December 24, 2007 Look into a program called Forms To Go. It will help with many things as well as this issue and requires NO knowledge of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422425 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks ohdang888 for sharing your code, So its just one .php file that i have to create with this code inside? <?php if (!isset($_POST['submit'])) {?> <form method="post"> E-Mail:<input type="text" size="15" maxlength="30" name="email"/> <input type="submit" name="submit" value="Submit"/> <form> <?php } else { $email = $_POST["email"]; $emailfile = "../emaillist.txt"; $FH = fopen($emailfile, 'a') or die("can't open file"); fwrite($FH,$email . ','); //LOOK AT THIS PART fclose($FH); } ?> Or i have to separate the code in an html code and php...? OH, and Northern Flame, isnt the same <?php //Add item to list if(isset($_POST['submit']) && $_POST['mailing_list_name'] != "" && $_POST['mailing_list_email'] != "") { $file_ptr = fopen("list.txt", "a+") or die("Couldn't create new file"); fwrite($file_ptr, $_POST['mailing_list_name'] . "\r\n"); fwrite($file_ptr, $_POST['mailing_list_email'] . "\r\n\r\n"); fclose($file_ptr); } ?> Than <?php //Add item to list if(isset($_POST['submit']) && $_POST['mailing_list_name'] != "" && $_POST['mailing_list_email'] != "") { $file_ptr = fopen("list.txt", "a+") or die("Couldn't create new file"); fwrite($file_ptr, $_POST['mailing_list_name'] . "\r\n"); fwrite($file_ptr, $_POST['mailing_list_email'] . "\r\n\r\n"); fclose($file_ptr); } ?> If it is not, i save that code in my subscribe.html, and change it to subscribe.php? After i change it, i upload subscribe.php, createlists.php, and lists.txt (CHMOD 777)? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422483 Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 http://www.w3schools.com/php/php_syntax.asp Glance through or read "Comments in PHP" please. You can mix HTML and PHP easily, and that's actually done a lot of the time.... The basic thing you would want to follow would be: $added = false; if($_POST) { if(<vars validate>) { //add to file if(<Added to file>) { $added = true; } } } if($added == true) { //success message } else { ?> HTML for form here <?php //or you could use heredoc format: echo <<<HERE <!--html for form here --> HERE; //ory ou could just use echos, with a little escaping echo '<html for form here>'; } Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422505 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Check this, i have this code, it works pretty good, writes the email to the file and eveything, but when i click submit, the screen goes white, and in the address bar it appears: http://www.mydomain.com/addemail.php?email=testemail%40email.com&submit=Submit What can i do so when they click submit, they redirect to a thank page? Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422508 Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 //<code to add address to file> header("Location: http://yoursite.com/thanks.html"); Or, you could just make the submit page the thank you page. Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422514 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Heres my code: test.html: <form action='addemail.php' method='GET'> E-mail: <input name="email" type="text" /> <input name="submit" type="submit" value="Submit" /> <input name="reset" type="reset" value="Reset" /> </form> addemail.php: <?php if (isset($_GET['submit'])){ $email = $_GET['email']; //adding a new line character so that each email address has its own line $email = "$email \n"; //opening the file for writing $textfile = fopen("emails.txt","a"); //writing the email fwrite($textfile, $email); //closing the textfile fclose($textfile); } ?> And lists.txt (CHMOD 777) Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422515 Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 <?php if (isset($_GET['submit'])){ $email = $_GET['email']; //adding a new line character so that each email address has its own line $email = "$email \n"; //opening the file for writing $textfile = fopen("emails.txt","a"); //writing the email fwrite($textfile, $email); //closing the textfile fclose($textfile); } ?> <h1>Thank you!</h1> Thanks for subscribing! Or, if you want it to go to a different page: <?php if (isset($_GET['submit'])){ $email = $_GET['email']; //adding a new line character so that each email address has its own line $email = "$email \n"; //opening the file for writing $textfile = fopen("emails.txt","a"); //writing the email fwrite($textfile, $email); //closing the textfile fclose($textfile); } header("Location: http://yoursite.com/thanks.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422517 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Thank you, ill try them, ill tell you if they work Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422529 Share on other sites More sharing options...
juapo2 Posted December 24, 2007 Author Share Posted December 24, 2007 Than you every1 for all your help!! TOPIC SOLVED!! check my subscription form: http://richithebest.co.nr/newsletter.html Quote Link to comment https://forums.phpfreaks.com/topic/82968-solved-help-doing-script/#findComment-422570 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.