Overtone Posted February 10, 2010 Share Posted February 10, 2010 <html> <body> <form action = "newsletter.php" method = "post"> Name: <input type ="text" name = "First Name"/><br><br> Email: <input type ="text" name ="Email Address"/> <input type = "submit"/> <?php $file = "ContactList.txt"; $name = Name; $handle = fopen("ContactList.txt","r+"); $email = $_POST["Email Address"]; fwrite($handle, $email); //heres the line that wont write properly fclose($handle); ?> </body> </html> up until i added the post message it was just writing a strign i had $email equal to. whats going wrong? Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/ Share on other sites More sharing options...
Catfish Posted February 10, 2010 Share Posted February 10, 2010 Depending on what the problem actually is, i'm guessing $_POST['Email Address'] doesn't exists, doesn't have a value given to it or is mispelt. Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/#findComment-1010191 Share on other sites More sharing options...
Overtone Posted February 10, 2010 Author Share Posted February 10, 2010 no no it exists. ts there fine. its just writing blank. ive already made it in the html, im just not sure its getting to the php correctly Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/#findComment-1010193 Share on other sites More sharing options...
Catfish Posted February 10, 2010 Share Posted February 10, 2010 if it's writing nothing to the file i can only imagine the value is not being passed as expected, which means what i said in the first reply. you have some options - 1. validate the fwrite command is working: if (fwrite($handle, $email)) { // succeeded continue } else { // failed - error } 2. use file_put_contents instead of fopen / fwrite etc. http://au2.php.net/manual/en/function.file-put-contents.php 3. double check all spelling of your variable names, verify the data actually exists with print_r etc. print_r($_POST); 4. Try writing $_POST['Email Address'] directly to the file fwrite($handle, $_POST['Email Address']); Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/#findComment-1010198 Share on other sites More sharing options...
wildteen88 Posted February 10, 2010 Share Posted February 10, 2010 Try to avoid using spaces when naming fields. An underscore is a good replacement for spaces. However what is most likely happing is your web browser is converting the spaces into a underscore. Try using $_POST['Email_Address'] instead. Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/#findComment-1010258 Share on other sites More sharing options...
Overtone Posted February 11, 2010 Author Share Posted February 11, 2010 Try to avoid using spaces when naming fields. An underscore is a good replacement for spaces. However what is most likely happing is your web browser is converting the spaces into a underscore. Try using $_POST['Email_Address'] instead. YES! thats what was wrong. simple syntax but somethinheg i completely overlooked. thanks very much mate Link to comment https://forums.phpfreaks.com/topic/191648-why-wont-this-write-anymore/#findComment-1010821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.