Jump to content

Writing data to a .txt file


awert

Recommended Posts

Hey im making a site which allows the user to type in their e-mail address and send it to my "emails.txt" file. Its not really working though...It seems like everything is right but it doesnt add it: Heres part of the code for the site:

method=get then action=next.php" name="theForm" id="theForm">

 

and this is the whole next.php:

<?php
header("my url ");
$handle =

fopen("emails.txt", "a");
foreach($_GET as

$variable => $value) {
fwrite($handle,

$variable);
fwrite($handle, "=");


fwrite($handle, $value);
fwrite($handle,

"\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>

 

Im pretty new to php so if you could help it would be great

 

Thanks in advance

Link to comment
Share on other sites

this should do for flat file

<?php
if(!empty($_GET)){
$handle = fopen("emails.txt", "a");
foreach($_GET as $key => $value) {
	$tempstring = $key."=".$value."\n";
	fwrite($handle,$tempstring);
}
fclose($handle);
}
?>

 

I think you are bloating the data you are putting in sine the key is always the same,  should just be $tempstring = $value."\n"; but its your method

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.