/    Sign up×
Community /Pin to ProfileBookmark

Submit form helps please

im new here so i dont know if im posting this in the right place, but i need to make a simple submit form with a text box, and have what ever the user submited save to a text file, seperated by spaces

for example if a person types in his email and hits submit, then another person does the same on the website it goes to file and the file looks like this:

[email][email protected][/email] [email][email protected][/email] so@on and@soforthe

to post a comment
Full-stack Developer

13 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 03.2005 — You'll need to use some sort of server-side processing, such as PHP, Perl, ASP, etc. The first step therefore will be to find out what server side processing your web host supports.
Copy linkTweet thisAlerts:
@mike288authorDec 03.2005 — php, it has mysql in it
Copy linkTweet thisAlerts:
@NogDogDec 03.2005 — Here are the essentials which you could elaborate upon to get the look and feel you want. (Save the file with a .php extension.)
[code=php]
<?php
/* form and form handler for adding email addresses to a text file */
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<title>Page title</title>
<style type="text/css">
<!--

-->
</style>
</head>
<body>
<?php
if(isset($_POST['email'])) # process form submission
{
$email = trim($_POST['email']);
if(empty($email))
{
echo "<h1>Error</h1>n<p>You must enter an email address</p>n";
}
else
{
$handle = fopen("emails.txt", "a") or
die("Unable to open emails.txt for appending");
fwrite($handle, "$email ") or die("Write to emails.txt failed");
fclose($handle);
echo "<h2>Email successfully added to list</h2>n";
echo "<p>Thank you for your submission.</p>n";
}
}
else # display form to submit email address:
{
echo <<<EOD
<h1>Submit Email Address to List</h1>
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p><label>Email Address:
<input type="text" name="email" size="20" maxlength="40">
</label</p>
<p><input type="submit" value="Save Email"></p>
</form>
EOD;

}
?>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — thank you
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — actually im getting a parse error on line 45 were u echo <<<Eod
Copy linkTweet thisAlerts:
@NogDogDec 04.2005 — Works fine for me. Only thing I can think of without seeing your code is to make sure the line that just says [b]EOD;[/b] (at the end of the form) has no white space at the beginning or end of the line (i.e., do not indent it at all).
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — no that line is fine, its the line 45 were it says echo <<<EOD

it gets a parse error on line 45 and says something like unexpected "<" was expecting ";" or ","
Copy linkTweet thisAlerts:
@NogDogDec 04.2005 — Well, like I said, it works fine for me. If you want to post your version of the code, maybe I can see something. Odds are there's a missiong quote, paren, bracket, or semicolon somwhere before the line where it fails.
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — i just coppied and pasted ur code, i didnt alter it any, i wanted to see if it worked first
Copy linkTweet thisAlerts:
@NogDogDec 04.2005 — Well, something is different. In my version, the [b]echo <<<EOD[/b] line is line number 36, but your error message says line number 45. (Perhaps your text editor has automatic word wrap turned on, and it broke a line where PHP doesn't like it to be broken?)
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — perhaps , i type my code in dream weaver, ill try it in note pad
Copy linkTweet thisAlerts:
@mike288authorDec 04.2005 — i tried it in note pad and it got a error on line 36 :


Parse error: parse error, unexpected T_SL, expecting ',' or ';' in /home/nynx/public_html/mike/test.php on line 36
Copy linkTweet thisAlerts:
@NogDogDec 05.2005 — Sorry, got me stumped: I do not get any such error.
×

Success!

Help @mike288 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...