Click to See Complete Forum and Search --> : Submit form helps please


mike288
12-03-2005, 02:40 PM
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:

thereemail@gmail.com theotherguys@email.com so@on and@soforthe

NogDog
12-03-2005, 03:29 PM
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.

mike288
12-03-2005, 04:25 PM
php, it has mysql in it

NogDog
12-03-2005, 05:39 PM
Here are the essentials which you could elaborate upon to get the look and feel you want. (Save the file with a .php extension.)

<?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>

mike288
12-04-2005, 12:13 AM
thank you

mike288
12-04-2005, 12:18 AM
actually im getting a parse error on line 45 were u echo <<<Eod

NogDog
12-04-2005, 02:29 AM
Works fine for me. Only thing I can think of without seeing your code is to make sure the line that just says EOD; (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).

mike288
12-04-2005, 11:58 AM
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 ","

NogDog
12-04-2005, 12:13 PM
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.

mike288
12-04-2005, 01:12 PM
i just coppied and pasted ur code, i didnt alter it any, i wanted to see if it worked first

NogDog
12-04-2005, 01:51 PM
Well, something is different. In my version, the echo <<<EOD 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?)

mike288
12-04-2005, 02:06 PM
perhaps , i type my code in dream weaver, ill try it in note pad

mike288
12-04-2005, 02:29 PM
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

NogDog
12-04-2005, 08:23 PM
Sorry, got me stumped: I do not get any such error.