Jump to content

Why wont this write anymore?


Overtone

Recommended Posts

<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

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']);

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.